MINI MINI MANI MO
Rem
Rem $Header: oracler/migration/oreuser/imp/dstorestg.sql /main/4 2016/10/21 11:02:24 qinwan Exp $
Rem
Rem dstorestg.sql
Rem
Rem Copyright (c) 2013, 2016, Oracle and/or its affiliates.
Rem All rights reserved.
Rem
Rem NAME
Rem dstorestg.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 MODIFIED (MM/DD/YY)
Rem qinwan 10/13/16 - add column ver
Rem qinwan 06/17/15 - handle refdbobject table
Rem gayyappa 12/11/13 - Created
Rem
Rem BEGIN SQL_FILE_METADATA
Rem SQL_SOURCE_FILE: oracler/migration/oreuser/imp/dstorestg.sql
Rem SQL_SHIPPED_FILE:
Rem SQL_PHASE:
Rem SQL_STARTUP_MODE: NORMAL
Rem SQL_IGNORABLE_ERRORS: NONE
Rem SQL_CALLING_FILE:
Rem END SQL_FILE_METADATA
SET ECHO ON
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 80
SET TRIMSPOOL ON
SET TAB OFF
SET PAGESIZE 100
WHENEVER SQLERROR EXIT SQL.SQLCODE
--Rem add column ver if not exists
DECLARE
column_exists number;
BEGIN
-- add column if not exists
select count(*) into column_exists from all_tab_cols
where owner='SYSTEM' and table_name='TMPRQDATASTOREOBJECT' and
column_name='VER';
IF (column_exists = 0) THEN
EXECUTE IMMEDIATE 'ALTER TABLE SYSTEM.TMPRQDATASTOREOBJECT ' ||
'ADD ver VARCHAR2(16) default ''1.5''';
END IF;
END;
/
SHOW ERRORS;
--Rem create staging tables
create table tmprqdsstg as select * from system.tmprqdatastore where dsid < 0;
alter table tmprqdsstg add ( newdsid number);
create table tmprqdsobjstg as select * from system.tmprqdatastoreobject where dsid < 0;
alter table tmprqdsobjstg add( newobjid number, newdsid number);
create table tmprqrefdbobjstg as select * from system.tmprqrefdbobject where refobjid < 0;
alter table tmprqrefdbobjstg add(newrefobjid number);
create table tmprqdsrefstg as select * from system.tmprqdatastorerefdbobject where objid < 0;
alter table tmprqdsrefstg add(newobjid number, newrefobjid number);
create table tmprqdsaccessstg as select * from system.tmprqdatastoreaccess where dsid < 0;
alter table tmprqdsaccessstg add ( newdsid number);
set autocommit off
whenever sqlerror exit rollback
---populate data into staging tables
insert into tmprqdsstg (dsid, dsowner, dsname, cdate, description,
tabname, newdsid)
select dsid, dsowner, dsname, cdate, description,
tabname, rqsys.rq$datastore_seq.nextval from tmprqdatastore;
insert into tmprqdsobjstg(objid, dsid, objname, class, objsize, length, nrow, ncol, ver, newobjid, newdsid)
select objid, a.dsid, objname, class, objsize, length, nrow, ncol, ver,
rqsys.rq$datastore_seq.nextval, t.newdsid
from tmprqdatastoreobject a, tmprqdsstg t
where a.dsid = t.dsid;
insert into tmprqrefdbobjstg(refobjid, refobjname, refobjtype, refobjparm, refobjowner, newrefobjid)
select s.refobjid, s.refobjname, s.refobjtype, s.refobjparm, s.refobjowner,
o.object_id
from tmprqrefdbobject s, all_objects o
where o.owner = s.refobjowner and
o.object_name = upper(case s.refobjtype when'rqScript' then s.refobjname || '_V' else s.refobjname end) and
o.object_type = upper(case s.refobjtype when'rqScript' then 'VIEW' when 'model' then 'MINING MODEL' else s.refobjtype end);
insert into tmprqdsrefstg(objid, refobjid, newobjid, newrefobjid)
select t.objid, t.refobjid, o.newobjid, s.newrefobjid
from tmprqdatastorerefdbobject t, tmprqdsobjstg o, tmprqrefdbobjstg s
where o.objid = t.objid and s.refobjid = t.refobjid;
insert into tmprqdsaccessstg (dsid, grantee, newdsid)
select a.dsid, b.grantee, a.newdsid
from tmprqdsstg a, system.tmprqdatastoreaccess b
where a.dsid = b.dsid;
commit;
--enable constraints and check they are valid
WHENEVER SQLERROR EXIT SQL.SQLCODE
alter table tmprqdsstg add constraint tmp_pk_dsid PRIMARY KEY ( newdsid);
alter table tmprqdsstg add constraint tmp_uk_dsname UNIQUE (dsowner, dsname);
alter table tmprqdsobjstg add constraint tmp_pk_objid PRIMARY KEY ( newobjid );
alter table tmprqdsobjstg add constraint tmp_fk_dsid FOREIGN KEY(newdsid) references tmprqdsstg(newdsid);
alter table tmprqdsobjstg add constraint tmp_uk_dsobjname UNIQUE (dsID, objname);
alter table tmprqrefdbobjstg add constraint tmp_pk_refobjid PRIMARY KEY(newrefobjid);
alter table tmprqdsrefstg add constraint tmp_fk_objid FOREIGN KEY(newobjid) references tmprqdsobjstg(newobjid);
alter table tmprqdsrefstg add constraint tmp_fk_refid FOREIGN KEY(newrefobjid) references tmprqrefdbobjstg(newrefobjid);
alter table tmprqdsrefstg add constraint tmp_uk_objrefid UNIQUE (newobjid, newrefobjid);
alter table tmprqdsaccessstg add constraint tmp_fk_dsaccessid FOREIGN KEY(newdsid) references tmprqdsstg(newdsid);
alter table tmprqdsaccessstg add constraint tmp_uk_dsaccessid UNIQUE (newdsid, grantee);
exit;
OHA YOOOO