MINI MINI MANI MO

Path : /opt/oracle/product/18c/dbhomeXE/md/admin/
File Upload :
Current File : //opt/oracle/product/18c/dbhomeXE/md/admin/seme121.sql

Rem
Rem $Header: sdo/admin/seme121.sql /main/21 2017/05/26 16:34:20 rjanders Exp $
Rem
Rem seme121.sql
Rem
Rem Copyright (c) 2013, 2017, Oracle and/or its affiliates. 
Rem All rights reserved.
Rem
Rem    NAME
Rem      seme121.sql - <one-line expansion of the name>
Rem
Rem    DESCRIPTION
Rem      <short description of component this file declares/defines>
Rem
Rem    NOTES
Rem      <other useful comments, qualifications, etc.>
Rem
Rem    BEGIN SQL_FILE_METADATA 
Rem    SQL_SOURCE_FILE: sdo/admin/seme121.sql 
Rem    SQL_SHIPPED_FILE: md/admin/seme121.sql
Rem    SQL_PHASE: DOWNGRADE
Rem    SQL_STARTUP_MODE: NORMAL 
Rem    SQL_IGNORABLE_ERRORS: NONE 
Rem    SQL_CALLING_FILE: NONE
Rem    END SQL_FILE_METADATA
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    rjanders    05/10/17 - #26037683: Raise 'when other' exceptions
Rem    rjanders    04/27/17 - Correct "SQL_PHASE" metadata values
Rem    matperry    03/07/17 - stack 12.2 downgrade
Rem    sravada     01/11/17 - bug 25370681
Rem    echong      08/17/16 - downgrade rdf_model_internal
Rem    matperry    07/20/16 - update for sem_indextype_im signature change from
Rem                           C library refactor
Rem    matperry    01/27/16 - #22578872 upgrade problem with sem_indextype_im
Rem                           type
Rem    anestrad    12/17/15 - Add semremovbdy
Rem    anestrad    12/07/15 - Alter RDF_DTYPE_INDEX_INFO
Rem    echong      11/19/15 - improve order-by processing
Rem    anestrad    07/14/15 - Add calls to data_122_exists
Rem    anestrad    07/09/15 - Drop RDF_CRS_URI$ table
Rem    matperry    06/10/15 - drop sdo_rdf_ddl_trigger
Rem    anestrad    05/15/15 - Drop geom column from RDF_VALUE$
Rem    anestrad    02/19/15 - Drop sem_match_nl
Rem    anestrad    11/14/14 - Drop update context
Rem    matperry    10/24/14 - drop new sdo_rdf_triple_s constructors
Rem    matperry    09/05/14 - refactor to make sparql_update invoker rights
Rem    matperry    05/12/14 - drop sparql update components
Rem    matperry    03/12/14 - update for pg_match
Rem    matperry    12/06/13 - drop GROUP_CONCAT_VC
Rem    matperry    11/19/13 - Created

Rem ********************************************************************
Rem #16473696: Indicate Oracle-Supplied object
@@?/rdbms/admin/sqlsessstart.sql
Rem ********************************************************************

-----------------------------------------------------------------------------------------------
-- The "e" script reverts the component's data dictionary back from release NNN+1 to release --
-- NNN. Since the cmpdbdwg.sql script calls the script for the downgrade release, these      --
-- scripts are stacked in the reverse order. They are called in the context of the NEW       --
-- server, before the RDBMS itself is downgraded. Set the version to the release version     --
-- (3 digits), not a patch version, in the dbms_registry.downgraded procedure invocation.    --
-----------------------------------------------------------------------------------------------

-- drop package and type bodies for a cleaner downgrade
prompt calling semremovbdy ...
@@semremovbdy.sql
prompt ... done calling semremovbdy

alter session set current_schema=MDSYS;
set define on;

-- make sure we do the downgrade without errors --
whenever sqlerror continue;

-- downgrade to 12.2 first --
@@seme122.sql

alter session set current_schema=MDSYS;

-- First mark that we are downgrading --
begin
  EXECUTE IMMEDIATE '
    UPDATE MDSYS.RDF_PARAMETER
    SET description = :1
    WHERE namespace = :2 and
          attribute = :3'
  USING 'DOWNGRADING','MDSYS','SEM_VERSION';

  EXCEPTION WHEN OTHERS THEN 
    SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
      'SEM_INSTALL: seme121: set downgrade in rdf_parameter: '||SQLERRM);
end;
/

declare
  sem_exists number := 0;
begin

  -- if semantics doesn't exist we need a dummy sdo_sem_downgrade package 
  select count(*) into sem_exists
  from SYS.all_objects
  where owner = 'MDSYS' and object_name = 'SDO_RDF_TRIPLE_S'; 

  if (sem_exists = 0) then
    begin
      execute immediate '
        create or replace package mdsys.sdo_sem_downgrade_utl as
          function data_122_exists(notify_level in integer)
          return boolean;
        end sdo_sem_downgrade_utl;';

      exception when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: seme121: sdo_sem_downgrade_utl: '||SQLERRM);
    end;
  end if;

end;
/
show errors;

-- Check data compatibility with 12.1 --
declare
  sem_exists number := 0;
begin

  select count(*) into sem_exists
  from SYS.all_objects
  where owner = 'MDSYS' and object_name = 'SDO_RDF_TRIPLE_S'; 

  if (sem_exists > 0) then

    if (mdsys.sdo_sem_downgrade_utl.data_122_exists(0)) then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'Semantics data is not compatible with version 12.1.0.1.0. Not downgrading to Release 12.1.');
        raise_application_error(-20000, 
          'Semantics data is not compatible with version 12.1.0.1.0');
    end if;

  end if;

end;
/
show errors;

-- DROP packages, views, and classes that were added in the new release

-- DROP force any new types, operators, and indextypes;
prompt dropping new types ...

declare
  sem_exists number := 0;
  object_not_found exception;
  pragma exception_init(object_not_found, -04043);
  synonym_not_found exception;
  pragma exception_init(synonym_not_found, -01432);
  trigger_not_found exception;
  pragma exception_init(trigger_not_found, -04080);
begin

  select count(*) into sem_exists
  from SYS.all_objects
  where owner = 'MDSYS' and object_name = 'SDO_RDF_TRIPLE_S'; 

  if (sem_exists > 0) then
    if (not(mdsys.sdo_sem_downgrade_utl.data_122_exists(0))) then

      ----------- SPARQL 1.1 Varchar2 Aggregates --------
      ----------- Introduced in 12.1.0.2.0 --------------
      begin
        execute immediate 'drop type MDSYS.SPARQL_Group_Concat_VC force';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop SPARQL_Group_Concat_VC type: '||SQLERRM);
      end;

      begin
        execute immediate 'drop type MDSYS.SPARQL_Sample_VC force';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
            'SEM_INSTALL: seme121: drop SPARQL_Sample_VC type: '||SQLERRM);
      end;

      begin
        execute immediate 'drop type MDSYS.SPARQL_min_VC force';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop SPARQL_min_VC type: '||SQLERRM);
      end;

      begin
        execute immediate 'drop type MDSYS.SPARQL_max_VC force';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop SPARQL_max_VC type: '||SQLERRM);
      end;

      begin
        execute immediate 'drop function mdsys.sparql_groupconcat_vc';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sparql_groupconcat_vc function: '||SQLERRM);
      end;

      begin
        execute immediate 'drop function mdsys.sparql_sampleagg_vc';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sparql_sampleagg_vc function: '||SQLERRM);
      end;

      begin
        execute immediate 'drop function mdsys.sparql_minagg_vc';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sparql_minagg_vc function: '||SQLERRM);
      end;

      begin
        execute immediate 'drop function mdsys.sparql_maxagg_vc';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sparql_maxagg_vc function: '||SQLERRM);
      end;

      begin
        execute immediate 'drop public synonym SEM_APIS_GROUPCONCAT_VC';
        exception
          when synonym_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sem_apis_groupconcat_vc synonym: '||SQLERRM);
      end;

      begin
        execute immediate 'drop public synonym SEM_APIS_SAMPLE_VC';
        exception 
          when synonym_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sem_apis_sample_vc synonym: '||SQLERRM);
      end;

      begin
        execute immediate 'drop public synonym SEM_APIS_MIN_VC';
        exception 
          when synonym_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sem_apis_min_vc synonym: '||SQLERRM);
      end;

      begin
        execute immediate 'drop public synonym SEM_APIS_MAX_VC';
        exception 
          when synonym_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sem_apis_max_vc synonym: '||SQLERRM);
      end;

      --------------- SPARQL_SERVICE -----------
      ----------- Introduced in 12.1.0.2.0 -----
      begin
        execute immediate 'drop public synonym SPARQL_SERVICE';
        exception 
          when synonym_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sparql_service synonym: '||SQLERRM);
      end;

      begin
        execute immediate 'drop function mdsys.SPARQL_SERVICE';
        exception 
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sparql_service function: '||SQLERRM);
      end;

      begin
        execute immediate 'drop type mdsys.SPARQL_SERVICE_IMPL_T';
        exception 
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
              'SEM_INSTALL: seme121: drop sparql_service_impl_t type: '||SQLERRM);
      end;

      begin
        execute immediate 'drop context SDO_SEM_HTTP_CTX';
        exception 
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop context sdo_sem_http_ctx: '||SQLERRM);
      end;

      begin
        execute immediate 'drop package mdsys.SDO_SEM_HTTP_CTX';
        exception 
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop package sdo_sem_http_ctx: '||SQLERRM);
      end;

      ------------------- PG_MATCH ---------------
      --------- Introduced in 12.2.0.1.0 ---------
      begin
        execute immediate 'drop public synonym PG_MATCH';
        exception 
          when synonym_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop synonym pg_match: '||SQLERRM);
      end;

      begin
        execute immediate 'drop public synonym SDO_PG_MATCH';
        exception 
          when synonym_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop synonym sdo_pg_match: '||SQLERRM);
      end;

      begin
        execute immediate 'drop function mdsys.PG_MATCH';
        exception 
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop function pg_match: '||SQLERRM);
      end;

      begin
        execute immediate 'drop type mdsys.PG_MATCH_IMPL_T';
        exception 
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop type pg_match_impl_t: '||SQLERRM);
      end;

      ------------------ SEM_MATCH_NL  ------------------
      --------- Introduced in 12.2 
      begin
        execute immediate 'drop public synonym SEM_MATCH_NL';
        exception 
          when synonym_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop synonym sem_match_nl: '||SQLERRM);
      end;

      begin
        execute immediate 'drop function mdsys.SEM_MATCH_NL';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop function sem_match_nl: '||SQLERRM);
      end;

      begin
        execute immediate 'drop type mdsys.SEM_MATCH_NL_IMPL_T';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop type sem_match_nl_impl_t: '||SQLERRM);
      end;

      ------------------- SDO_SEM_UPDATE_CTX ---------------
      -- Introduced in 12.2 for SPARQL UPDATE
      begin
        execute immediate 'drop context SDO_SEM_UPDATE_CTX';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop context sdo_sem_update_ctx: '||SQLERRM);
      end;

      begin
        execute immediate 'drop package mdsys.SDO_SEM_UPDATE_CTX';
        exception
          when object_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop package sdo_sem_update_ctx: '||SQLERRM);
      end;

      ------------------- sdo_rdf_ddl_trigger ---------------
      -- Introduced in 12.2 to eliminate dependency on SDO DDL trigger
      begin
        execute immediate 'drop trigger mdsys.sdo_rdf_ddl_trigger';
        exception
          when trigger_not_found then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: drop sdo_rdf_ddl_trigger: '||SQLERRM);
      end;

    end if;
  end if;
end;
/

prompt ... finished dropping new types

-- ALTER TYPE for existing types back to their prior release definitions
prompt alter types back to prior definitions ...

declare
  sem_exists number := 0;
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
begin

  select count(*) into sem_exists
  from SYS.all_objects
  where owner = 'MDSYS' and object_name = 'SDO_RDF_TRIPLE_S'; 

  if (sem_exists > 0) then
    if (not(mdsys.sdo_sem_downgrade_utl.data_122_exists(0))) then

      ------- new function signatures for sem_indextype_im --------
      -- Add back old signatures dropped in 12.2 for Unicode Support
      begin
        execute immediate 
          'alter type sem_indextype_im
            add
            STATIC FUNCTION ODCIIndexStart (sctx IN OUT  sem_indextype_im,
                                            ia           SYS.ODCIindexinfo,
                                            op           SYS.ODCIPredInfo,
                                            qi           SYS.ODCIQueryInfo,
                                            strt         NUMBER,
                                            stop         NUMBER,
                                            pred_expr    VARCHAR2,
                                            obj          VARCHAR2,
                                            models       MDSYS.RDF_Models,
                                            rulebases    MDSYS.RDF_Rulebases,       
                                            idxStatus_in VARCHAR2,
                                            env          SYS.ODCIEnv) RETURN NUMBER';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
            'SEM_INSTALL: seme121: alter type sem_indextype_im add ODCIIndexStart1: '||SQLERRM);
      end;
      begin
        execute immediate 
          'alter type sem_indextype_im
            add
            STATIC FUNCTION ODCIIndexStart (sctx IN OUT  sem_indextype_im,
                                            ia           SYS.ODCIindexinfo,
                                            op           SYS.ODCIPredInfo,
                                            qi           SYS.ODCIQueryInfo,
                                            strt         NUMBER,
                                            stop         NUMBER,
                                            pred_expr    VARCHAR2,
                                            obj          VARCHAR2,
                                            models       MDSYS.RDF_Models,
                                            rulebases    MDSYS.RDF_Rulebases,
                                            dist_lower   INTEGER,
                                            dist_upper   INTEGER,       
                                            env          SYS.ODCIEnv) RETURN NUMBER';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
            'SEM_INSTALL: seme121: alter type sem_indextype_im add ODCIIndexStart2: '||SQLERRM);
      end;

      begin
        execute immediate 
          'alter type sem_indextype_im
            add
            STATIC FUNCTION ODCIIndexStart (sctx IN OUT  sem_indextype_im,
                                            ia           SYS.ODCIindexinfo,
                                            op           SYS.ODCIPredInfo,
                                            qi           SYS.ODCIQueryInfo,
                                            strt         NUMBER,
                                            stop         NUMBER,
                                            pred_expr    VARCHAR2,
                                            obj          VARCHAR2,
                                            models       MDSYS.RDF_Models,
                                            rulebases    MDSYS.RDF_Rulebases,   
                                            idxStatus_in VARCHAR2,
                                            dist_lower   INTEGER,    
                                            dist_upper   INTEGER,
                                            env          SYS.ODCIEnv) RETURN NUMBER';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
            'SEM_INSTALL: seme121: alter type sem_indextype_im add ODCIIndexStart3: '||SQLERRM);
      end;

      begin
        execute immediate 
          'alter type sem_indextype_im
            add
            STATIC FUNCTION ODCIIndexStart (sctx IN OUT  sem_indextype_im,
                                            ia           SYS.ODCIindexinfo,
                                            op           SYS.ODCIPredInfo,
                                            qi           SYS.ODCIQueryInfo,
                                            strt         NUMBER,
                                            stop         NUMBER,
                                            pred_expr    VARCHAR2,
                                            obj          VARCHAR2,
                                            models       MDSYS.RDF_Models,
                                            rulebases    MDSYS.RDF_Rulebases,       
                                            env          SYS.ODCIEnv) RETURN NUMBER';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
            'SEM_INSTALL: seme121: alter type sem_indextype_im add ODCIIndexStart4: '||SQLERRM);
      end;

      begin
        execute immediate
          'alter type sem_indextype_im
            add
            MEMBER FUNCTION ODCIIndexClose (env SYS.ODCIEnv) RETURN NUMBER';
        exception when others then
              SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
                'SEM_INSTALL: seme121: alter sem_indextype_im add ODCIIndexClose: '||SQLERRM);
      end;

      -- Drop new signatures Introduced in 12.2 for Unicode Support
      begin
        execute immediate 
          'alter type sem_indextype_im
            drop
            STATIC FUNCTION ODCIIndexStart (sctx IN OUT  sem_indextype_im,
                                            ia           SYS.ODCIindexinfo,
                                            op           SYS.ODCIPredInfo,
                                            qi           SYS.ODCIQueryInfo,
                                            strt         NUMBER,
                                            stop         NUMBER,
                                            pred_expr    VARCHAR2  character set any_cs,
                                            obj          VARCHAR2  character set any_cs,
                                            models       MDSYS.RDF_Models,
                                            rulebases    MDSYS.RDF_Rulebases,       
                                            idxStatus_in VARCHAR2,
                                            env          SYS.ODCIEnv) RETURN NUMBER cascade';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
            'SEM_INSTALL: seme121: alter type sem_indextype_im drop ODCIIndexStart1: '||SQLERRM);
      end;
      begin
        execute immediate 
          'alter type sem_indextype_im
            drop
            STATIC FUNCTION ODCIIndexStart (sctx IN OUT  sem_indextype_im,
                                            ia           SYS.ODCIindexinfo,
                                            op           SYS.ODCIPredInfo,
                                            qi           SYS.ODCIQueryInfo,
                                            strt         NUMBER,
                                            stop         NUMBER,
                                            pred_expr    VARCHAR2  character set any_cs,
                                            obj          VARCHAR2  character set any_cs,
                                            models       MDSYS.RDF_Models,
                                            rulebases    MDSYS.RDF_Rulebases,
                                            dist_lower   INTEGER,
                                            dist_upper   INTEGER,       
                                            env          SYS.ODCIEnv) RETURN NUMBER cascade';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
            'SEM_INSTALL: seme121: alter type sem_indextype_im drop ODCIIndexStart2: '||SQLERRM);
      end;

      begin
        execute immediate 
          'alter type sem_indextype_im
            drop
            STATIC FUNCTION ODCIIndexStart (sctx IN OUT  sem_indextype_im,
                                            ia           SYS.ODCIindexinfo,
                                            op           SYS.ODCIPredInfo,
                                            qi           SYS.ODCIQueryInfo,
                                            strt         NUMBER,
                                            stop         NUMBER,
                                            pred_expr    VARCHAR2  character set any_cs,
                                            obj          VARCHAR2  character set any_cs,
                                            models       MDSYS.RDF_Models,
                                            rulebases    MDSYS.RDF_Rulebases,   
                                            idxStatus_in VARCHAR2,
                                            dist_lower   INTEGER,    
                                            dist_upper   INTEGER,
                                            env          SYS.ODCIEnv) RETURN NUMBER cascade';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
            'SEM_INSTALL: seme121: alter type sem_indextype_im drop ODCIIndexStart3: '||SQLERRM);
      end;

      begin
        execute immediate 
          'alter type sem_indextype_im
            drop
            STATIC FUNCTION ODCIIndexStart (sctx IN OUT  sem_indextype_im,
                                            ia           SYS.ODCIindexinfo,
                                            op           SYS.ODCIPredInfo,
                                            qi           SYS.ODCIQueryInfo,
                                            strt         NUMBER,
                                            stop         NUMBER,
                                            pred_expr    VARCHAR2  character set any_cs,
                                            obj          VARCHAR2  character set any_cs,
                                            models       MDSYS.RDF_Models,
                                            rulebases    MDSYS.RDF_Rulebases,       
                                            env          SYS.ODCIEnv) RETURN NUMBER cascade';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
            'SEM_INSTALL: seme121: alter type sem_indextype_im drop ODCIIndexStart4: '||SQLERRM);
      end;

      begin
        execute immediate
          'alter type sem_indextype_im
            drop
            MEMBER FUNCTION ODCIIndexClose (self IN OUT nocopy sem_indextype_im,
                                            env SYS.ODCIEnv) RETURN NUMBER';
        exception when others then
              SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
                'SEM_INSTALL: seme121: alter sem_indextype_im drop ODCIIndexClose: '||SQLERRM);
      end;

      ----------- new constructors in SDO_RDF_TRIPLE_S ------------
      -- Introduced in 12.2 for SPARQL UPDATE
      begin
        execute immediate 
          'alter type sdo_rdf_triple_s 
             drop constructor function sdo_rdf_triple_s(
                                          model_name varchar2,
                                          nonauto    INTEGER,
                                          subject    varchar2,
                                          property   varchar2,
                                          object     varchar2) 
             return self as result';
        exception
          when compile_errors then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: alter type sdo_rdf_triple_s: '||SQLERRM);
      end;

      begin
        execute immediate 
          'alter type sdo_rdf_triple_s 
             drop constructor function sdo_rdf_triple_s(
                                          model_name varchar2,
                                          nonauto    INTEGER,
                                          subject    varchar2,
                                          property   varchar2,
                                          object     clob) 
             return self as result';
        exception
          when compile_errors then NULL;
          when others then
            SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
              'SEM_INSTALL: seme121: alter type sdo_rdf_triple_s: '||SQLERRM);
      end;

    end if;
  end if;
end;
/

prompt ... finished altering types back to prior definitions

-- ALTER OPERATOR and INDEXTYPE back to their prior release bindings and properties

-- UPDATE new columns to values appropriate for the old release and for when the database is re-upgraded
prompt dropping new columns and constraints ...

declare
  network_exists number;
  obj_exists number;
begin
  -- see if RDF Network is present in DB
  SELECT count(*) INTO network_exists FROM SYS.ALL_TABLES
  WHERE table_name='RDF_VALUE$' AND owner='MDSYS';

  if (network_exists > 0) then
    if (not(mdsys.sdo_sem_downgrade_utl.data_122_exists(0))) then
      begin
        execute immediate
         'ALTER TABLE mdsys.rdf_value$
          SET UNUSED (order_type, order_num, order_date, geom)';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
            'SEM_INSTALL: seme121: rdf_value$: '||SQLERRM);
      end;

      begin
        execute immediate
         'ALTER TABLE mdsys.rdf_model_internal$
          SET UNUSED (inmemory)';
        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
            'SEM_INSTALL: seme121: rdf_model_internal$: '||SQLERRM);
      end;

      begin
        execute immediate
         'CREATE OR REPLACE VIEW RDF_DTYPE_INDEX_INFO (
            DATATYPE, INDEX_NAME, STATUS, TABLESPACE_NAME)
          AS
            SELECT idx_map.dtype DATATYPE, a.index_name INDEX_NAME, a.status STATUS, a.tablespace_name TABLESPACE_NAME
            FROM SYS.all_indexes a,
            (
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#decimal'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#double'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#float'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#integer'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#int'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#nonPositiveInteger'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#negativeInteger'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#long'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#short'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#byte'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#nonNegativeInteger'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#unsignedLong'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#unsignedInt'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#unsignedShort'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#unsignedByte'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$NUMERIC_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#positiveInteger'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$BOOL_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#boolean'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$STR_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#string'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$DATE_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#date'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$TIME_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#time'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$DATETIME_IDX'' index_name, ''http://www.w3.org/2001/XMLSchema#dateTime'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$GEO_IDX'' index_name, ''http://xmlns.oracle.com/rdf/geo/WKTLiteral'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$GEO_IDX'' index_name, ''http://www.opengis.net/ont/geosparql#wktLiteral'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$TEXT_IDX'' index_name, ''http://xmlns.oracle.com/rdf/text'' dtype from SYS.DUAL)
              UNION ALL
             (select ''RDF_V$LIKE_IDX'' index_name, ''http://xmlns.oracle.com/rdf/like'' dtype from SYS.DUAL)
            ) idx_map
            WHERE owner=''MDSYS'' AND table_name=''RDF_VALUE$'' AND
                  a.index_name = idx_map.index_name';

        execute immediate 'CREATE OR REPLACE VIEW SEM_DTYPE_INDEX_INFO AS SELECT * FROM MDSYS.RDF_DTYPE_INDEX_INFO';

        execute immediate 'GRANT READ ON SEM_DTYPE_INDEX_INFO     TO PUBLIC';
        execute immediate 'GRANT READ ON RDF_DTYPE_INDEX_INFO     TO PUBLIC';

        exception when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
            'SEM_INSTALL: seme121: sem_dtype_index_info: '||SQLERRM);
      end;

    end if;
  end if;
end;
/

prompt finished dropping new columns and constraints

-- Undo any modifications that were made to user objects during the upgrade.

-- Drop new tables
prompt dropping new tables ...

declare
  sem_exists number := 0;
  network_exists number := 0;
begin

  select count(*) into sem_exists
  from SYS.all_objects
  where owner = 'MDSYS' and object_name = 'SDO_RDF_TRIPLE_S'; 

  if (sem_exists > 0) then
    if (not(mdsys.sdo_sem_downgrade_utl.data_122_exists(0))) then

       -- see if RDF Network is present in DB
       SELECT count(*) INTO network_exists FROM SYS.ALL_TABLES
       WHERE table_name='RDF_VALUE$' AND owner='MDSYS';


       if (network_exists > 0) then

         begin
           execute immediate
            'DROP TABLE mdsys.rdf_crs_uri$';
           exception when others then
             SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
               'SEM_INSTALL: seme121: rdf_crs_uri$: '||SQLERRM);
         end;

       end if;

    end if;
  end if;
end;
/

prompt ... finished dropping new tables      

alter session set current_schema=SYS;

Rem ********************************************************************
Rem #16473696: Indicate Oracle-Supplied object
@@?/rdbms/admin/sqlsessend.sql
Rem ********************************************************************

OHA YOOOO