MINI MINI MANI MO

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

Rem
Rem $Header: sdo/admin/sdordfty.sql /main/56 2017/05/26 16:34:20 rjanders Exp $
Rem
Rem sdordfty.sql
Rem
Rem Copyright (c) 2004, 2017, Oracle and/or its affiliates. 
Rem All rights reserved.
Rem
Rem    NAME
Rem      sdordfty.sql - sdo_rdf_type
Rem
Rem    DESCRIPTION
Rem      The sdo_rdf_triple is a persistent datatype for RDF triple storage in NDM
Rem
Rem    NOTES
Rem      OID is required if the user-defined type is persistent and
Rem      instances of this type will be shared across databases.
Rem      Use SYS_OP_GUID to generate valid, unique OIDs.
Rem      
Rem
Rem    BEGIN SQL_FILE_METADATA
Rem    SQL_SOURCE_FILE: sdo/admin/sdordfty.sql
Rem    SQL_SHIPPED_FILE: md/admin/sdordfty.sql
Rem    SQL_PHASE: SDORDFTY
Rem    SQL_STARTUP_MODE: NORMAL
Rem    SQL_IGNORABLE_ERRORS: NONE
Rem    SQL_CALLING_FILE: sdo/admin/catsem.sql
Rem    END SQL_FILE_METADATA
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    rjanders    03/23/17 - #25437999: Remove 'when others then NULL'
Rem                           handlers
Rem    rjanders    03/09/17 - Add missing SQL_FILE_METADATA information
Rem    sravada     01/11/17 - bug 25370681
Rem    matperry    07/19/16 - add self argument to
Rem                           sem_indextype_im.ODCIIndexClose
Rem    anestrad    02/29/16 - Grant read on RDF_PARAMETER
Rem    matperry    01/27/16 - #22578872 upgrade problem with sem_indextype_im
Rem                           type
Rem    anestrad    12/16/15 - Remove Oracle Text APIS grants
Rem    anestrad    10/30/15 - Allow any_cs in sem_indextype_im
Rem    rjanders    09/16/15 - #21825604: Remove WITH GRANT OPTION from PUBLIC
Rem    rjanders    01/17/15 - long identifier project phase 1
Rem    matperry    10/24/14 - add non-autonomous constructors for
Rem                           sdo_rdf_triple_s
Rem    matperry    10/03/13 - parallel enable sdo_rdf_term constructors
Rem    rjanders    09/16/13 - OCCS: Remove hardtabs
Rem    rjanders    03/15/13 - #16473696: Start/End _ORACLE_SCRIPT
Rem                           initialization
Rem    matperry    10/01/12 - wrap create or replace synonym with begin end to
Rem                           catch errors
Rem    matperry    07/24/12 - add methods related to canonicalization to
Rem                           sdo_rdf_term
Rem    matperry    06/22/12 - make repeatable to be upgrade friendly
Rem    matperry    06/12/12 - add new constructor to sdo_rdf_term
Rem    jazarago    05/28/12 - Add prefix/suffix name split function for
Rem                           SDO_RDF_TERM
Rem    matperry    05/15/12 - add rdf_entailments type
Rem    matperry    04/13/12 - add vname_prefix and vname_suffix to sdo_rdf_term
Rem    jazarago    03/06/12 - Extend sdo_rdf_term for aggregates usability
Rem    jazarago    12/13/11 - Add sdo_rdf_term_list data type
Rem    matperry    08/29/11 - add sdo_rdf_term object type
Rem    alwu        12/17/10 - name graph local inference
Rem    sdas        11/22/10 - XbranchMerge sdas_ng_11.2.0.2.0_11.2.0.3.0 from
Rem                           st_sdo_11.2.0
Rem    sdas        11/22/10 - XbranchMerge sdas_ng_11.2.0.2.0 from
Rem    matperry    11/05/10 - grant execute on Oracle Text APIs to MDSYS
Rem    sdas        08/28/10 - add GET_MODEL method
Rem    matperry    07/06/10 - add RDF_Graphs type
Rem    matperry    04/02/10 - grant execute on Oracle Text APIs to MDSYS
Rem    vkolovsk    11/03/09 - moved sdosemsam type creation and removal to
Rem                           sdordfty and semremov
Rem    matperry    05/05/09 - move creation of RDF_Models, etc. to here
Rem    matperry    05/05/09 - add type creation for types associated with
Rem                           sem_related operator
Rem    vkolovsk    04/07/09 - add tablespace name for rdf_parameter
Rem    ayalaman    01/05/09 - parameters table for network options
Rem    ayalaman    12/21/08 - ols label generator types
Rem    sdas        02/08/07 - type change: replace RDF_T_ID with RDF_C_ID
Rem    sdas        02/05/07 - bulk-load perf: use default SDO_RDF_TRIPLE_S
Rem                           constructor
Rem    sdas        10/23/06 - make SDO_RDF_TRIPLE_S invokers priv
Rem    sdas        06/15/06 - avoid conflict in SDO_RDF_TRIPLE_S constructor 
Rem    alwu        06/14/06 - add one more constructor 
Rem    nalexand    10/13/05 - remove compile after alter type 
Rem    nalexand    10/10/05 - add alter type syntax. 
Rem    nalexand    10/07/05 - add lock_model to start_batch$ 
Rem    nalexand    10/06/05 - add bnode batch constructors 
Rem    nalexand    09/26/05 - add constructor for long_literals 
Rem    nalexand    09/16/05 - add batch mode constructor 
Rem    sravada     04/28/05 - type methods execute as the definer 
Rem    nalexand    01/24/05 - add reif const (mn, s_rdf_t_id, prop, 
Rem                           o_rdf_t_id) 
Rem    nalexand    01/12/05 - clob bn constructor; add get_sub, get_prop, get_obj 
Rem    nalexand    12/15/04 - increase varchar2(2000) 
Rem    sravada     11/10/04 - change to create or replace 
Rem    nalexand    09/27/04 - add reif constructor
Rem    nalexand    09/20/04 - add reif constructor
Rem    nalexand    09/09/04 - add rdf_value$ table and rdf_p_id to type 
Rem    nalexand    07/20/04 - changing object to CLOB
Rem    nalexand    06/24/04 - blank node constructor 
Rem    nalexand    06/21/04 - changing name to sdo_rdf_triple_s (for storage)
Rem    nalexand    04/16/04 - 
Rem    nalexand    04/07/04 - testing first constructor 
Rem    nalexand    04/06/04 - Make subject and property namespaces required
Rem    nalexand    04/01/04 - Created
Rem

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

Rem SELECT TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD:HH24:MI:SS') FROM SYS.DUAL;
Rem SELECT SYS_OP_GUID() FROM SYS.DUAL;

----------------------------------------------------------------------------
--===========            PLEASE READ BEFORE MODIFYING          ===========--
----------------------------------------------------------------------------
--                                                                        --
-- The idea is to make this script repeatable so that it is               --
-- upgrade friendly, so follow these steps:                               --
--                                                                        --
-- 1) CREATE OR REPLACE TYPE with the original type definition            --
--    from the first time that it is added. Then do not change this.      --
-- 2) To drop a method/attribute                                          --
--    a) drop the method/attribute in this file                           --
-- 3) To add a method/attribute                                           --
--    a) add the method/attribute in this file                            --
--    b) drop method/attribute in semeXXX.sql file used during downgrade  --
--       e.g. for release 12.1, modify seme112.sql                        --
--                                                                        --
-- Note that you have to wrap each modification in a PL/SQL block to      --
-- catch errors (e.g. drop a method that's not there) so that the         --
-- install does not fail.                                                 --
----------------------------------------------------------------------------


-- SDO_RDF_TERM introduced in 12.1 --
declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
   begin
    execute immediate 
    ' CREATE OR REPLACE TYPE sdo_rdf_term 
      TIMESTAMP ''2012-02-22:12:57:38''
      OID ''BB0F4DD691A761A4E043BAB9E50A2E27''
      authid current_user
      AS OBJECT 
        (
         value_type    VARCHAR2(10),
         value_name    VARCHAR2(4000),
         vname_prefix  VARCHAR2(4000),
         vname_suffix  VARCHAR2(512),
         literal_type  VARCHAR2(1000),
         language_type VARCHAR2(80),
         long_value    CLOB,
         ctx1          VARCHAR2(4000),

         CONSTRUCTOR FUNCTION sdo_rdf_term(
           value_type    VARCHAR2,
           value_name    VARCHAR2,
           literal_type  VARCHAR2,
           language_type VARCHAR2,
           long_value    CLOB)
         RETURN SELF AS RESULT DETERMINISTIC PARALLEL_ENABLE, 

         CONSTRUCTOR FUNCTION sdo_rdf_term(
           value_type    VARCHAR2,
           value_name    VARCHAR2,
           literal_type  VARCHAR2,
           language_type VARCHAR2,
           long_value    CLOB,
           check_null    PLS_INTEGER)
         RETURN SELF AS RESULT DETERMINISTIC PARALLEL_ENABLE,

         CONSTRUCTOR FUNCTION sdo_rdf_term(
           value_type    VARCHAR2,
           value_name    VARCHAR2,
           literal_type  VARCHAR2,
           language_type VARCHAR2,
           long_value    CLOB,
           ctx1          VARCHAR2)
         RETURN SELF AS RESULT DETERMINISTIC PARALLEL_ENABLE,

         CONSTRUCTOR FUNCTION sdo_rdf_term(
           rdf_term_str  VARCHAR2)
         RETURN SELF AS RESULT DETERMINISTIC PARALLEL_ENABLE,

         MAP MEMBER FUNCTION compare 
         RETURN VARCHAR2 DETERMINISTIC PARALLEL_ENABLE,

         MEMBER FUNCTION setValueName (
           vnameStr      VARCHAR2,
           value_type    VARCHAR2,
           return_typ    NUMBER)
         RETURN VARCHAR2 DETERMINISTIC PARALLEL_ENABLE,

         MEMBER FUNCTION nonCanonTermStr
         RETURN VARCHAR2 DETERMINISTIC PARALLEL_ENABLE,

         MEMBER FUNCTION canonTermStr
         RETURN VARCHAR2 DETERMINISTIC PARALLEL_ENABLE,

         MEMBER FUNCTION toCanonTerm
         RETURN SDO_RDF_TERM DETERMINISTIC PARALLEL_ENABLE
         )';
      exception
        when dependent_objects then NULL;
        when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
            'SEM_INSTALL: sdordfty: create sdo_rdf_term: '||SQLERRM);
    end;
end;
/
SHOW ERRORS;

GRANT EXECUTE ON mdsys.sdo_rdf_term TO PUBLIC;

begin
  execute immediate
    'CREATE OR REPLACE PUBLIC SYNONYM sdo_rdf_term FOR mdsys.sdo_rdf_term';
  exception
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create or replace synonym sdo_rdf_term: '||SQLERRM);
end;
/
SHOW ERRORS;

-- SDO_RDF_TRIPLE introduced in 10.2 --
declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
   begin
    execute immediate 
    ' CREATE OR REPLACE TYPE sdo_rdf_triple
      AS OBJECT 
        (subject VARCHAR2(4000),
         property VARCHAR2(4000),
         object VARCHAR2(10000)) ';
    exception
      when dependent_objects then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: create sdo_rdf_tripe: '||SQLERRM);
    end;
end;
/

SHOW ERRORS;

GRANT EXECUTE ON mdsys.sdo_rdf_triple TO PUBLIC;

begin
  execute immediate
    'CREATE OR REPLACE PUBLIC SYNONYM sdo_rdf_triple FOR mdsys.sdo_rdf_triple';
  exception
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create or replace synonym sdo_rdf_triple: '||SQLERRM);
end;
/
SHOW ERRORS;


-- SDO_RDF_TRIPLE_S introduced in 10.2 (using 11.1 version) --
declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
   begin
    execute immediate 
' CREATE OR REPLACE TYPE sdo_rdf_triple_s
  TIMESTAMP ''2004-04-01:14:30:35''
  OID ''D70B0A2BA8AE3606E030578CD3051938''
  authid current_user
  AS OBJECT
       (rdf_c_id NUMBER,
        rdf_m_id NUMBER,
        rdf_s_id NUMBER,
        rdf_p_id NUMBER,
        rdf_o_id NUMBER,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        subject VARCHAR2,
                                        property VARCHAR2,
                                        object VARCHAR2)
        RETURN SELF AS RESULT DETERMINISTIC,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        subject VARCHAR2,
                                        property VARCHAR2,
                                        object CLOB)
        RETURN SELF AS RESULT DETERMINISTIC,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        sub_or_bn VARCHAR2,
                                        property VARCHAR2,
                                        obj_or_bn VARCHAR2,
                                        bn_m_id NUMBER)
        RETURN SELF AS RESULT DETERMINISTIC,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        sub_or_bn VARCHAR2,
                                        property VARCHAR2,
                                        object CLOB,
                                        bn_m_id NUMBER)
        RETURN SELF AS RESULT DETERMINISTIC,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        rdf_t_id NUMBER)
        RETURN SELF AS RESULT DETERMINISTIC,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        rdf_t_id NUMBER,
                                        property VARCHAR2,
                                        object VARCHAR2)
        RETURN SELF AS RESULT DETERMINISTIC,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        subject VARCHAR2,
                                        property VARCHAR2,
                                        rdf_t_id NUMBER)
        RETURN SELF AS RESULT DETERMINISTIC,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        s_rdf_t_id NUMBER,
                                        property VARCHAR2,
                                        o_rdf_t_id NUMBER)
        RETURN SELF AS RESULT DETERMINISTIC,
        CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_name VARCHAR2,
                                        reif_subject VARCHAR2,
                                        reif_property VARCHAR2,
                                        subject VARCHAR2,
                                        property VARCHAR2,
                                        object VARCHAR2)
        RETURN SELF AS RESULT DETERMINISTIC,
        MEMBER FUNCTION get_triple RETURN SDO_RDF_TRIPLE DETERMINISTIC,
        MEMBER FUNCTION get_object RETURN CLOB DETERMINISTIC,
        MEMBER FUNCTION get_subject RETURN VARCHAR2 DETERMINISTIC, 
        MEMBER FUNCTION get_property RETURN VARCHAR2 DETERMINISTIC
        ) ';
      exception
        when dependent_objects then NULL;
        when others then
          SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
            'SEM_INSTALL: sdordfty: create sdo_rdf_triple_s: '||SQLERRM);
    end;
end;
/

Rem
Rem First, remove any methods/attributes that are no longer used
Rem to make it upgrade friendly
Rem

Rem
Rem Now we add the current set of non-original functions to make it
Rem upgrade friendly
Rem

declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
begin
   begin
    execute immediate
    ' ALTER TYPE sdo_rdf_triple_s
      ADD MEMBER FUNCTION get_obj_value RETURN VARCHAR2 
      DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add get_obj_value): '||SQLERRM);
   end;

   begin
    execute immediate
    ' ALTER TYPE sdo_rdf_triple_s
      ADD MEMBER FUNCTION is_object_clob RETURN VARCHAR2 
      DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add is_object_clob): '||SQLERRM);
   end;

   begin
    execute immediate
    ' ALTER TYPE sdo_rdf_triple_s
      ADD MEMBER FUNCTION get_model RETURN VARCHAR2 
      DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add get_model): '||SQLERRM);
   end;

   begin
    execute immediate 
    ' ALTER TYPE sdo_rdf_triple_s
            ADD CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_id NUMBER,
                                        subject VARCHAR2,
                                        property VARCHAR2,
                                        object VARCHAR2,
                                        in_mode VARCHAR2)
            RETURN SELF AS RESULT DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add constructor1): '||SQLERRM);
   end;

   begin
    execute immediate 
    ' ALTER TYPE sdo_rdf_triple_s
            ADD CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_id NUMBER,
                                        subject VARCHAR2,
                                        property VARCHAR2,
                                        object CLOB,
                                        in_mode VARCHAR2)
            RETURN SELF AS RESULT DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add constructor2): '||SQLERRM);
   end;

   begin
    execute immediate 
    ' ALTER TYPE sdo_rdf_triple_s
            ADD CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_id NUMBER,
                                        sub_or_bn VARCHAR2,
                                        property VARCHAR2,
                                        obj_or_bn VARCHAR2,
                                        in_mode VARCHAR2,
                                        bn_m_id NUMBER)
            RETURN SELF AS RESULT DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add constructor3): '||SQLERRM);
   end;

   begin
    execute immediate 
    ' ALTER TYPE sdo_rdf_triple_s
            ADD CONSTRUCTOR FUNCTION sdo_rdf_triple_s(model_id NUMBER,
                                        sub_or_bn VARCHAR2,
                                        property VARCHAR2,
                                        object CLOB,
                                        in_mode VARCHAR2,
                                        bn_m_id NUMBER)
            RETURN SELF AS RESULT DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add constructor4): '||SQLERRM);
   end;

   -- non-autonomous constructors for supporting serializable transactions
   -- with SPARQL UPDATE
   --
   -- Note: Ideally, we would add a default argument to the existing constructor
   -- by dropping the exising one and adding new one with an additional 
   -- integer default 0 argument. This would create a problem during downgrade
   -- though because the constructor we are dropping is in the original type
   -- creation block, so after we drop the new version of the the constructor
   -- the original one would not get created after downgrade because the create 
   -- or replace type statement always fails when any data is present in the 
   -- rdf network. Instead, we are just adding a new constructor with an integer
   -- argument. We can just drop this one during downgrade with no issues.
   begin
    execute immediate 
    ' ALTER TYPE sdo_rdf_triple_s
            ADD CONSTRUCTOR FUNCTION sdo_rdf_triple_s(
                                        model_name VARCHAR2,
                                        nonauto    NUMBER,
                                        subject    VARCHAR2,
                                        property   VARCHAR2,
                                        object     VARCHAR2)
            RETURN SELF AS RESULT DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add constructor5): '||SQLERRM);
   end;

   begin
    execute immediate 
    ' ALTER TYPE sdo_rdf_triple_s
            ADD CONSTRUCTOR FUNCTION sdo_rdf_triple_s(
                                        model_name VARCHAR2,
                                        nonauto    NUMBER,
                                        subject    VARCHAR2,
                                        property   VARCHAR2,
                                        object     CLOB)
            RETURN SELF AS RESULT DETERMINISTIC CASCADE';
    exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: sdo_rdf_triple_s (add constructor6): '||SQLERRM);
   end;

end;
/   


GRANT EXECUTE ON mdsys.sdo_rdf_triple_s TO PUBLIC;
 
begin
  execute immediate
    'CREATE OR REPLACE PUBLIC SYNONYM sdo_rdf_triple_s FOR mdsys.sdo_rdf_triple_s';
  exception
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create or replace synonym sdo_rdf_triple_s: '||SQLERRM);
end;
/
SHOW ERRORS;


declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_CLOBS as VARRAY(32767) of CLOB';
  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_clobs: '||SQLERRM);
end;
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_Models as table of varchar2(25)';
   exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_models: '||SQLERRM);
end;
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_RuleBases as table of varchar2(25)';
  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_rulebases: '||SQLERRM);
end;
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_Graphs as table of varchar2(4000)';
  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_graphs: '||SQLERRM);
end;
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_Entailments as table of varchar2(25)';
  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_entailments: '||SQLERRM);
end;
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_Alias as object (
      namespace_id  varchar2(128),
      namespace_val varchar2(4000))';
  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_alias: '||SQLERRM);
end;  
/
SHOW ERRORS

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_Aliases as table of RDF_Alias';
  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_aliases: '||SQLERRM);
end;  
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate 'create or replace TYPE sem_sameas_rec as object (s number, e number)';

  exception 
    when dependent_objects then NULL;
    when others then 
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: create sem_sameas_rec: '||SQLERRM);
end;
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate 'create or replace TYPE sem_sameas_list is TABLE OF sem_sameas_REC';

  exception 
    when dependent_objects then NULL;
    when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: create sem_sameas_list: '||SQLERRM);
end;
/  

-- varcharArray, longVarcharArray and int_array for internal use
declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_varcharArray as varray(32767) of varchar2(30)';
  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_vachararray: '||SQLERRM);
end;  
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
    'create or replace type RDF_longVarcharArray as varray(32767)
       of varchar2(4000)';
  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create rdf_longvarchararray: '||SQLERRM);
end;  
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate 
    'create or replace type mdsys.int_array as varray(1000) of int';

  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create int_array: '||SQLERRM); 
end;
/

declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin 
  execute immediate
    'create or replace type MDSYS.SDO_RDF_TERM_LIST as varray(32767) of sdo_rdf_term';

  exception
    when dependent_objects then NULL;
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create sdo_rdf_term_list: '||SQLERRM);
end;
/

GRANT EXECUTE ON mdsys.sdo_rdf_term_list TO PUBLIC;

begin
  execute immediate
    'CREATE OR REPLACE PUBLIC SYNONYM sdo_rdf_term_list FOR mdsys.sdo_rdf_term_list';
  exception
    when others then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
        'SEM_INSTALL: sdordfty: create or replace synonym sdo_rdf_term_list: '||SQLERRM);
end;
/
SHOW ERRORS;



--
--- OLS support: types for extensible label generator 
--
/*****************************************************************************/
/*** Type used for Extensible Label Generator for Inferred data            ***/
/*****************************************************************************/
declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
execute immediate '
create or replace type mdsys.rdfsa_resource as object (
  res_id      VARCHAR2(100),
  res_type    NUMBER,
  res_labels  MDSYS.INT_ARRAY,
  constructor function rdfsa_resource (res_id VARCHAR2, res_type number)
                                            return self as result,
  constructor function rdfsa_resource (res_id VARCHAR2,
         res_type number, res_label number) return self as result,
  constructor function rdfsa_resource (res_id VARCHAR2, res_type number,
                res_labels mdsys.int_array) return self as result,
  member function getResource return VARCHAR2,
  member function getLabelCount return number,
  member function getLabel(idx number default 1) return number
)'; 

  exception
      when dependent_objects then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: create rdfsa_resource: '||SQLERRM); 
end;
/

show errors; 

-- Dummy type implementation: actual type body will be installed when OLS 
-- is enabled for RDF using sdordfsa.sql 
-- Dummy implementation needed in case sdordfsa is not installed because
-- methods referenced in other packages
create or replace type body mdsys.rdfsa_resource as 
  constructor function rdfsa_resource (res_id VARCHAR2, res_type number)
                                            return self as result is 
  begin
    null;
  end; 

  constructor function rdfsa_resource (res_id VARCHAR2, res_type number,
            res_label number) return self as result is 
  begin
    null;
  end;

  constructor function rdfsa_resource (res_id VARCHAR2, res_type number,
            res_labels mdsys.int_array) return self as result is
  begin
    null;
  end; 

  member function getResource return VARCHAR2 is 
  begin
    null;
  end; 

  member function getLabelCount return number is
  begin
    null; 
  end; 

  member function getLabel(idx number default 1) return number is
  begin
    null;
  end;
end;
/

show errors; 


/*****************************************************************************/
/**** Label generator stub for Extensible implementations                  ***/
/***  This type can be extended for custom label generators                ***/
/*****************************************************************************/
begin
execute immediate
'create or replace type mdsys.rdfsa_labelgen authid current_user as object (
  gen_option   NUMBER,

  -- 
  --- SETDEPRESOURCES : to set the dependent resources for the label   
  --- generator. Information about these resources will be passed to the
  --- the getNumericLabel method at runtime                              
  ---                                                                    
  --- Usage:  setDepResources(sem_rdfsa.USE_SUBJECT_LABEL+
  ---                         sem_rdfsa.USE_RULE_LABEL) 
  --
  final member procedure setDepResources(useres number), 

  -- 
  --- FINDOMINATINGOF : Find a clear dominating label out of the labels 
  --- passed in. -1 is returned if a clear dominating label is not found -- 
  final static function findDominatingOf(labels MDSYS.INT_ARRAY) return number, 

  --
  --- GETNUMERICLABEL : Extensible implementations for this type should   
  --- override this method to return a custom label based on the resources 
  --- passed in. The exact list of resources passed in is dependent on    
  --- options passed to the setDepResource method                        
  --
  member function getNumericLabel (subject   rdfsa_resource, 
                                   predicate rdfsa_resource, 
                                   object    rdfsa_resource, 
                                   rule      rdfsa_resource, 
                                   anteced   rdfsa_resource) 
       return number

) not final';

  exception
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: create rdfsa_labelgen: '||SQLERRM);
end;
/

show errors;

-- Dummy implementation needed in case sdordfsa is not installed because
-- methods are referenced in other packages
create or replace type body mdsys.rdfsa_labelgen is

  final member procedure setDepResources(useres number) is
  begin
    null;
  end;

  final static function findDominatingOf(labels MDSYS.INT_ARRAY)
       return number is
  begin
    null;
  end; 

  member function getNumericLabel (subject   rdfsa_resource,
                                   predicate rdfsa_resource,
                                   object    rdfsa_resource,
                                   rule      rdfsa_resource,
                                   anteced   rdfsa_resource)
       return number is
  begin
    null;
  end; 
end; 
/ 

SHOW ERRORS;

grant execute on mdsys.rdfsa_resource to public;

begin
  execute immediate
    'create or replace public synonym rdfsa_resource for  mdsys.rdfsa_resource'; 
  exception
      when others then
    SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
      'SEM_INSTALL: sdordfty: create or replace synonym rdfsa_resource: '||SQLERRM);
end;
/
SHOW ERRORS;


------- rdf_parameter table -------
declare
  name_exists exception;
  pragma exception_init(name_exists, -00955);
begin
  EXECUTE IMMEDIATE 'create table mdsys.rdf_parameter 
        (namespace   VARCHAR2(30), 
         attribute   VARCHAR2(30), 
         value       VARCHAR2(512), 
         description VARCHAR2(100), 
         constraint rdf_parameter_key primary key (namespace, attribute))
       organization index tablespace SYSAUX';

  exception 
    when name_exists then
      SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
        'CREATE TABLE rdf_parameter ERROR=' || SQLERRM);
    when others then 
      raise; 
end;
/
SHOW ERRORS;

GRANT READ ON mdsys.rdf_parameter TO PUBLIC;

-- 12.2: Change column size from 30 to 128

begin
  execute immediate
 ' alter table mdsys.rdf_parameter
   modify ( namespace VARCHAR2(128) ) ';
  exception
      when others then
    SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
      'ALTER TABLE rdf_parameter ERROR=' || SQLERRM);
end;
/
SHOW ERRORS

/*****************************************************************************/
/**** Types related to sem operators (Introduced in 11.1)                  ***/
/*****************************************************************************/
-------------- Serves as a reference to temporary btree pointer --------
declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
   'create or replace type sdo_bt_handle
    as object
    (
     btree RAW(4),
     shd   RAW(4)
    )';
  exception
      when dependent_objects then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: create sdo_bt_handle: '||SQLERRM);
end;
/

----------------------- indextype specification -----------------------------
declare
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
begin
  execute immediate
   'CREATE OR REPLACE TYPE sem_indextype_im authid current_user AS OBJECT
    ( 
      ---------- Variables --------------------
      curnum                NUMBER, -- cursor number
      dist_cur_num          NUMBER, -- ancillary cursor
      path_cur_num          NUMBER, -- ancillary cursor
      curr_rules_index      VARCHAR2(128), -- current rules index name
      models_in             MDSYS.RDF_Models,
      rulebases_in          MDSYS.RDF_Rulebases,

      bt_handle         MDSYS.SDO_BT_HANDLE, -- pointer to btree for sem_distance anc op
      using_bt          INTEGER, -- set to 1 if we are using temp bt for sem_distance
      keysz                     INTEGER, -- btree keysize in bytes
      datasz            INTEGER, -- btree datasize in bytes

      topk_opt          INTEGER, -- set to 1 if we are optimizing for top-k query
                                       -- else set to 0
      last_cutoff               INTEGER, -- last cutoff during evaluation of top-k query
      rows_covered              NUMBER,  -- number of rows covered so far according to stats
      direction         INTEGER, -- direction of top-k query 1 = asc, 0 = desc
      base_query                VARCHAR2(4000), -- base query for top-k optimization 
      pred_id           INTEGER, -- predicate id for this query
      stats_table               VARCHAR2(270), -- name of stats table for index stats

      distances         VARCHAR2(32000), -- cache for passing distances to anc op
      invalid_cache             INTEGER, -- set to 1 if cache is invalid, 0 otherwise

      ---------- Functions -------------------- 
      STATIC FUNCTION ODCIGetInterfaces (ifclist OUT SYS.ODCIObjectList) RETURN NUMBER,

      STATIC FUNCTION ODCIIndexCreate (ia    SYS.ODCIindexinfo,
                                       parms VARCHAR2,
                                       env   SYS.ODCIEnv) RETURN NUMBER,

      STATIC FUNCTION ODCIIndexDrop (ia  SYS.ODCIindexinfo,
                                     env SYS.ODCIEnv) RETURN NUMBER,

      STATIC FUNCTION ODCIIndexTruncate (ia  SYS.ODCIIndexInfo, 
                                         env SYS.ODCIEnv) RETURN NUMBER,

      STATIC FUNCTION ODCIIndexAlter (ia           SYS.ODCIIndexInfo, 
                                      parms IN OUT VARCHAR2,
                                      alter_option NUMBER,
                                      env          SYS.ODCIEnv) RETURN NUMBER,

      STATIC FUNCTION ODCIIndexInsert (ia     SYS.ODCIindexinfo,
                                       rid    varchar2,
                                       newval varchar2, 
                                       env    SYS.ODCIEnv) RETURN NUMBER,

      STATIC FUNCTION ODCIIndexDelete (ia     SYS.ODCIindexinfo,
                                       rid    varchar2,
                                       oldval varchar2,
                                       env    SYS.ODCIEnv) RETURN NUMBER,

      STATIC FUNCTION ODCIIndexUpdate (ia     SYS.ODCIindexinfo,
                                       rid    varchar2,
                                       oldval varchar2,
                                       newval varchar2,
                                       env    SYS.ODCIEnv) RETURN NUMBER,

      -- index ststaus optional parameter only --
      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,

      -- upper and lower bound optional parameters only --
      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,

      -- index status and upper and lower bound optional parameters -- 
      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,
      -- no optional parameters --
      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,


      MEMBER FUNCTION ODCIIndexFetch (self IN OUT nocopy sem_indextype_im,
                                      nrows    NUMBER,
                                      rids OUT SYS.ODCIridlist,
                                      env      SYS.ODCIEnv) RETURN NUMBER,

      MEMBER FUNCTION ODCIIndexClose (env SYS.ODCIEnv) RETURN NUMBER,

      STATIC FUNCTION ODCIIndexGetMetadata (ia           SYS.ODCIindexinfo,
                                            expversion   VARCHAR2,
                                            newblock OUT PLS_INTEGER,
                                            env          SYS.ODCIEnv) RETURN VARCHAR2

    )';
  exception
      when dependent_objects then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: create sem_indextype_im: '||SQLERRM);
end;
/
SHOW ERRORS

-------------------- Add ANY_CS to some arguments in 12.2 ----------------------
----------------------- Add new versions ---------------------------------------
-- index ststaus optional parameter only --
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
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  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';
  exception
      when compile_errors then NULL;
      when dependent_objects then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im add ODCIIndexStart1: '||SQLERRM);
end;
/
-- upper and lower bound optional parameters only --
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
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  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';
  exception
      when compile_errors then NULL;
      when dependent_objects then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im add ODCIIndexStart2: '||SQLERRM);
end;
/
-- index status and upper and lower bound optional parameters -- 
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
  dependent_objects exception;
  pragma exception_init(dependent_objects, -02303);
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  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';
  exception
      when compile_errors then NULL;
      when dependent_objects then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im add ODCIIndexStart3: '||SQLERRM);
end;
/
-- no optional parameters --
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
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  character set any_cs,
                                      obj          VARCHAR2  character set any_cs,
                                      models       MDSYS.RDF_Models,
                                      rulebases    MDSYS.RDF_Rulebases,       
                                      env          SYS.ODCIEnv) RETURN NUMBER';
  exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im add ODCIIndexStart4: '||SQLERRM);
end;
/

-- self argument --
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
begin
  execute immediate
    'alter type sem_indextype_im
      add
      MEMBER FUNCTION ODCIIndexClose (self IN OUT nocopy sem_indextype_im,
                                      env SYS.ODCIEnv) RETURN NUMBER';
  exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im add ODCIIndexClose: '||SQLERRM);
end;
/

----------------------- Drop old versions --------------------------------------
-- index ststaus optional parameter only --
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
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,
                                      obj          VARCHAR2,
                                      models       MDSYS.RDF_Models,
                                      rulebases    MDSYS.RDF_Rulebases,       
                                      idxStatus_in VARCHAR2,
                                      env          SYS.ODCIEnv) RETURN NUMBER
        cascade';
  exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im drop ODCIIndexStart1: '||SQLERRM);
end;
/
-- upper and lower bound optional parameters only --
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
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,
                                      obj          VARCHAR2,
                                      models       MDSYS.RDF_Models,
                                      rulebases    MDSYS.RDF_Rulebases,
                                      dist_lower   INTEGER,
                                      dist_upper   INTEGER,       
                                      env          SYS.ODCIEnv) RETURN NUMBER
        cascade';
  exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im drop ODCIIndexStart2: '||SQLERRM);
end;
/
-- index status and upper and lower bound optional parameters -- 
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
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,
                                      obj          VARCHAR2,
                                      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 compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im drop ODCIIndexStart3: '||SQLERRM);
end;
/
-- no optional parameters --
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
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,
                                      obj          VARCHAR2,
                                      models       MDSYS.RDF_Models,
                                      rulebases    MDSYS.RDF_Rulebases,       
                                      env          SYS.ODCIEnv) RETURN NUMBER
        cascade';
  exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im drop ODCIIndexStart4: '||SQLERRM);
end;
/

-- no self argument --
declare
  compile_errors exception;
  pragma exception_init(compile_errors, -22324);
begin
  execute immediate
    'alter type sem_indextype_im
      drop
      MEMBER FUNCTION ODCIIndexClose (env SYS.ODCIEnv) RETURN NUMBER';
  exception
      when compile_errors then NULL;
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: alter sem_indextype_im drop ODCIIndexClose: '||SQLERRM);
end;
/


----------------------- statistics type specification --------------------------
begin
  execute immediate
   'CREATE OR REPLACE TYPE sdo_sem_stats authid current_user AS OBJECT
    (
      curnum NUMBER,

      STATIC FUNCTION ODCIGetInterfaces (ifclist OUT sys.ODCIObjectList)
        RETURN NUMBER,

      STATIC FUNCTION ODCIStatsCollect (col sys.ODCIColInfo,
                                        options sys.ODCIStatsOptions,
                                        rawstats OUT RAW,
                                        env sys.ODCIEnv)
        RETURN NUMBER,

      STATIC FUNCTION ODCIStatsDelete (col sys.ODCIColInfo,
                                        env sys.ODCIEnv)
        RETURN NUMBER,

      STATIC FUNCTION ODCIStatsCollect (ia sys.ODCIIndexInfo,
                                        options sys.ODCIStatsOptions,
                                        rawstats OUT RAW,
                                        env sys.ODCIEnv)
        RETURN NUMBER,

      STATIC FUNCTION ODCIStatsDelete (ia sys.ODCIIndexInfo,
                                       statistics OUT RAW,
                                       env sys.ODCIEnv)
        RETURN NUMBER
    )';
  exception
      when others then
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE, 
          'SEM_INSTALL: sdordfty: create sdo_sem_stats: '||SQLERRM);
end;
/

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


OHA YOOOO