MINI MINI MANI MO
Rem
Rem $Header: sdo/admin/semu121.sql /main/19 2017/05/26 16:34:19 rjanders Exp $
Rem
Rem semu121.sql
Rem
Rem Copyright (c) 2014, 2017, Oracle and/or its affiliates.
Rem All rights reserved.
Rem
Rem NAME
Rem semu121.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/semu121.sql
Rem SQL_SHIPPED_FILE: md/admin/semu121.sql
Rem SQL_PHASE: UPGRADE
Rem SQL_STARTUP_MODE: NORMAL
Rem SQL_IGNORABLE_ERRORS: NONE
Rem SQL_CALLING_FILE: sdo/admin/semu112.sql
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 sravada 01/11/17 - bug 25370681
Rem matperry 03/08/16 - drop database-wide triggers to avoid problems in
Rem drop_rdf_network from a pdb
Rem anestrad 02/25/16 - Add need migration message in RDF_PARAMETER
Rem matperry 02/12/16 - get rid of unnecessary database-wide ddl triggers
Rem anestrad 01/22/16 - Add num and date materialized indexes to
Rem RDF_DTYPE_INDEX_INFO
Rem matperry 01/11/16 - remove VPD and WM during upgrade
Rem anestrad 11/30/15 - Add funcidx_status column to RDF_DTYPE_INDEX_INFO
Rem echong 11/19/15 - improve order-by processing
Rem czechar 08/14/15 - add SQL file metadata
Rem anestrad 07/14/15 - do not drop/add value_name
Rem anestrad 07/09/15 - Create RDF_CRS_URI$ table
Rem anestrad 05/15/15 - Add geom column on RDF_VALUE$
Rem matperry 09/03/14 - remove creation of insert and delete temporary
Rem tables
Rem anestrad 06/17/14 - Add CLOB column to update temporary tables
Rem matperry 06/02/14 - change sparql update temporary tables to on
Rem commit preserve rows
Rem matperry 05/12/14 - Created
Rem
Rem ********************************************************************
Rem #16473696: Indicate Oracle-Supplied object
@@?/rdbms/admin/sqlsessstart.sql
Rem ********************************************************************
------------------------------------------------------------------------------------------
-- The "u" script for each prior release performs the following actions to upgrade --
-- from release NNN to NNN+1. If NNN+1 is not the current release, then the "u" script --
-- invokes the script for release NNN+1, so that the upgrade is "stacked.". --
------------------------------------------------------------------------------------------
alter session set current_schema=MDSYS;
set define on;
-- make sure we do the upgrade without errors --
whenever sqlerror continue;
-- First mark that we are upgrading --
declare
valid_exists NUMBER;
upg_desc VARCHAR2(100);
begin
EXECUTE IMMEDIATE '
SELECT COUNT(*)
FROM MDSYS.RDF_PARAMETER
WHERE namespace = :1 and
attribute = :2 and
description IN (:3,:4)'
INTO valid_exists
USING 'MDSYS','SEM_VERSION','VALID','UPGRADING_VALID';
if (valid_exists > 0) then
upg_desc := 'UPGRADING_VALID';
else
upg_desc := 'UPGRADING_INVALID';
end if;
EXECUTE IMMEDIATE '
UPDATE MDSYS.RDF_PARAMETER
SET description = :1
WHERE namespace = :2 and
attribute = :3'
USING upg_desc,'MDSYS','SEM_VERSION';
COMMIT;
EXCEPTION WHEN OTHERS THEN
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: set upgrade in rdf_parameter: '||SQLERRM);
end;
/
prompt preparing semantic network for upgrade to version 12.2 ...
--/////////// Drop obsolete objects (views, packages, etc.) from prior release \\\\\\\\\\--
prompt dropping obsolete objects ...
declare
obj_cnt number;
vpd_enabled number;
vpd_views sys.ODCIVarchar2List :=
sys.ODCIVarchar2List('RDFVPD_POLICIES','RDFVPD_MODELS',
'RDFVPD_RESOURCE_REL','RDFVPD_PREDICATE_MDATA',
'RDFVPD_POLICY_CONSTRAINTS');
vpd_tables sys.ODCIVarchar2List :=
sys.ODCIVarchar2List('RDFVPD_POLICIES$','RDFVPD_MODELS$',
'RDFVPD_RESOURCE_REL$','RDFVPD_PREDICATE_MDATA$',
'RDFVPD_POLICY_CONSTRAINTS$',
'rdfvpd_policy_compl_constr$');
network_exists number;
table_not_found exception;
pragma exception_init(table_not_found, -00942);
trigger_not_found exception;
pragma exception_init(trigger_not_found, -04080);
begin
----------------------- Cleanup VPD ---------------------------
begin
-- Get rid of VPD if it is not enabled.
-- VPD is enabled if there is an existing policy
SELECT count(*) INTO obj_cnt FROM SYS.ALL_TABLES
WHERE table_name='RDFVPD_POLICIES$' AND owner='MDSYS';
if (obj_cnt > 0) then
execute immediate
'select count(*) from mdsys.rdfvpd_policies$'
into vpd_enabled;
if (vpd_enabled = 0) then
-- VPD objects have been created, but no VPD data exists,
-- so remove all VPD-related database objects.
for i in 1 .. vpd_views.count loop
begin
EXECUTE IMMEDIATE 'drop view mdsys.'||vpd_views(i);
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: cleanup VPD views: '||SQLERRM);
-- RAISE;
end;
end loop;
for i in 1 .. vpd_tables.count loop
begin
EXECUTE IMMEDIATE 'drop table mdsys.'||vpd_tables(i);
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: cleanup VPD tables: '||SQLERRM);
-- RAISE;
end;
end loop;
-- now remove entries for VPD from RDF_PARAMETER
begin
execute immediate
'delete from mdsys.rdf_parameter
where namespace=:1 and attribute=:2'
using 'COMPONENT','RDFVPD';
exception
when table_not_found then NULL;
when no_data_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: cleanup VPD from RDF_PARAMETER: '||SQLERRM);
-- RAISE;
end;
end if;
-- if VPD is enabled, then we will set an invalid status during semvalidate
else
-- VPD is installed but not enabled, so remove entries for VPD from RDF_PARAMETER
begin
execute immediate
'delete from mdsys.rdf_parameter
where namespace=:1 and attribute=:2'
using 'COMPONENT','RDFVPD';
exception
when table_not_found then NULL;
when no_data_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: cleanup VPD from RDF_PARAMETER: '||SQLERRM);
-- RAISE;
end;
end if;
exception
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: cleanup VPD: '||SQLERRM);
end;
------------------------ Cleanup WM ------------------------
-- Deinstallation of WM is complicated and we cannot call
-- the WM PL/SQL packages during upgrade, so we will mark
-- the installation as invalid until the user manually
-- uninstalls WM after upgrade. Note that WM is not installed
-- by default so this should be uncommon.
-- Get rid of sdo_sem_drop_trigger and sdo_sem_alter_trigger.
-- In 12.2 these are only created when an RDF network is created.
-- For multi-tenant, we need to drop these triggers everywhere
-- so that the won't be marked as database-wide objects. If a
-- network exists, these triggers will get created during semrelod,
-- which will make them local to a pdb. If they are marked as
-- database-wide, we will get an error when trying to drop the
-- trigger from a pdb during drop_rdf_network. If they are local,
-- there is no error.
begin
execute immediate 'drop trigger mdsys.sdo_sem_drop_trigger';
exception
when trigger_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: drop trigger sdo_sem_drop_trigger: '||SQLERRM);
-- RAISE;
end;
begin
execute immediate 'drop trigger mdsys.sdo_sem_alter_trigger';
exception
when trigger_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: drop trigger sdo_sem_alter_trigger: '||SQLERRM);
-- RAISE;
end;
end;
/
prompt finished dropping obsolete objects
--//////// ALTER tables to add/change columns and constraints for the new release \\\\\\\--
prompt adding new columns and constraints ...
declare
network_exists number;
obj_exists number;
object_exists exception;
pragma exception_init(object_exists, -00955);
column_exists exception;
pragma exception_init(column_exists, -01430);
unique_constraint exception;
pragma exception_init(unique_constraint, -00001);
table_not_found exception;
pragma exception_init(table_not_found, -00942);
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';
-- there is an issue with virtual columns here so we can't
-- drop/add value_name at this point because rdf_apis_internal
-- is invalid and value$hashCLOB index has a dependency on
-- rdf_apis_internal
if (network_exists > 0) then
begin
execute immediate
'alter table mdsys.rdf_value$
add (order_type number, order_num number,
order_date timestamp with time zone, geom mdsys.sdo_geometry)';
exception
when object_exists then NULL;
when table_not_found then NULL;
when column_exists then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: rdf_value$: '||SQLERRM);
-- RAISE;
end;
-- Order columns should be populated, but we cannot migrate
-- automatically, the user should perform the migration. We
-- mark the install as invalid and we add a need migration
-- message in RDF_PARAMETER
begin
execute immediate
'INSERT INTO MDSYS.RDF_PARAMETER
(namespace, attribute, value, description)
values(:1,:2,:3,:4)'
using 'MDSYS','RDF_VALUE$','INVALID_ORDER_COLUMNS',
'RDF_VALUE$ Table needs data migration with SEM_APIS.MIGRATE_DATA_TO_CURRENT';
COMMIT;
exception
when unique_constraint then NULL;
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: set invalid rdf_value$ in rdf_parameter: '||SQLERRM);
-- RAISE;
end;
end if;
end;
/
prompt finished adding new columns and constraints
--/////////////////////// Modify static tables for the new release \\\\\\\\\\\\\\\\\\\\\\--
--//////////// UPDATE existing columns as needed to reflect new algorithms, etc. \\\\\\\\--
--////////////////////// Create new types and tables for the release \\\\\\\\\\\\\\\\\\\\--
prompt creating new tables and views ...
declare
network_exists number;
obj_exists number;
tbs_name varchar2(130);
object_exists exception;
pragma exception_init(object_exists, -00955);
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
begin
execute immediate
'CREATE OR REPLACE VIEW RDF_DTYPE_INDEX_INFO (
DATATYPE, INDEX_NAME, STATUS, TABLESPACE_NAME, FUNCIDX_STATUS)
AS
SELECT idx_map.dtype DATATYPE, a.index_name INDEX_NAME, a.status STATUS, a.tablespace_name TABLESPACE_NAME,
a.funcidx_status FUNCIDX_STATUS
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$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#decimal'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#double'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#float'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#integer'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#int'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#nonPositiveInteger'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#negativeInteger'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#long'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#short'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#byte'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#nonNegativeInteger'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#unsignedLong'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#unsignedInt'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#unsignedShort'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' index_name, ''http://www.w3.org/2001/XMLSchema#unsignedByte'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$NUMERIC_MIDX'' 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$STRU_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$DATE_MIDX'' 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$TIME_MIDX'' 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$DATETIME_MIDX'' 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$GEO_MIDX'' index_name, ''http://xmlns.oracle.com/rdf/geo/WKTLiteral'' dtype from SYS.DUAL)
UNION ALL
(select ''RDF_V$GEO_MIDX'' 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: semu112: sem_dtype_index_info: '||SQLERRM);
end;
begin
execute immediate
'SELECT tablespace_name FROM SYS.ALL_TABLES
WHERE table_name=''RDF_VALUE$'' AND owner=''MDSYS'''
into tbs_name;
execute immediate
'CREATE TABLE rdf_crs_uri$(
srid NUMBER NOT NULL PRIMARY KEY
, crs_uri VARCHAR2(4000)
)
tablespace ' || SYS.DBMS_ASSERT.ENQUOTE_NAME(tbs_name, FALSE)||
' compress ';
exception
when object_exists then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semu121: rdf_crs_uri$: '||SQLERRM);
end;
end if;
end;
/
prompt ... finished creating new tables and views
--/// ALTER existing types to add/change attributes and methods for the new release \\\\\--
--////// GRANT any additional privileges required by MDSYS for the new release \\\\\\\\\\--
prompt ... finished preparing semantic network for upgrade to version 12.2
alter session set current_schema=SYS;
Rem ********************************************************************
Rem #16473696: Indicate Oracle-Supplied object
@?/rdbms/admin/sqlsessend.sql
Rem ********************************************************************
OHA YOOOO