forked from oracle-samples/db-sample-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkplug.sql
837 lines (742 loc) · 27.1 KB
/
mkplug.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
Rem
Rem $Header: rdbms/demo/schema/mkplug.sql /st_rdbms_12.1/2 2014/06/26 10:02:08 lokeskum Exp $
Rem
Rem mkplug.sql
Rem
Rem Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
Rem
Rem Permission is hereby granted, free of charge, to any person obtaining
Rem a copy of this software and associated documentation files (the
Rem "Software"), to deal in the Software without restriction, including
Rem without limitation the rights to use, copy, modify, merge, publish,
Rem distribute, sublicense, and/or sell copies of the Software, and to
Rem permit persons to whom the Software is furnished to do so, subject to
Rem the following conditions:
Rem
Rem The above copyright notice and this permission notice shall be
Rem included in all copies or substantial portions of the Software.
Rem
Rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Rem EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Rem MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Rem NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
Rem LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
Rem OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Rem WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Rem
Rem NAME
Rem mkplug.sql - plug in transportable tablespace EXAMPLE
Rem
Rem DESCRIPTION
Rem tbd
Rem
Rem NOTES
Rem The EXAMPLE tablespace only contains the Sample Schemas
Rem - CAUTION: Never use the Sample Schemas for
Rem anything other than demos and examples
Rem - USAGE: tbd
Rem - LOG FILES: The log files are written
Rem to the equivalent of $ORACLE_HOME/demo/schema/log
Rem If you edit the log file location further down in this
Rem script, use absolute pathnames
Rem
Rem MODIFIED (MM/DD/YY)
Rem lokeskum 06/25/14 - revert undo_management changes
Rem lokeskum 06/19/14 - XbranchMerge lokeskum_lrg-12263194 from main
Rem lokeskum 06/14/14 - include drop tablespace example
Rem dgagne 10/11/13 - backout previous change.
Rem dgagne 10/11/13 - tbs already read write after tts import
Rem jstenois 07/18/13 - Fix TERRITORY to be AMERICA; not AMERICAN
Rem dmatisha 12/05/12 - removing set TZ line because it is handled in
Rem tdss.tsc
Rem dmatisha 11/09/12 - setting correct TZ
Rem dmatisha 11/08/12 - fixing lrg 7324707
Rem celsbern 07/05/12 - adding oe_data_path parameter to mkplug.sql
Rem celsbern 04/24/12 - updating after cwm_user removal
Rem krajaman 03/21/12 - Temporary fix for CBD from Satish
Rem lokeskum 11/01/11 - include silent=banner paramter to impdp
Rem jmadduku 02/18/11 - Grant Unlimited Tablespace priv with RESOURCE
Rem celsbern 07/12/10 - added dump_path parameter
Rem celsbern 07/07/10 - removing call to mk_expdp_do.sql script
Rem celsbern 06/28/10 - fixing path for backup dfb file
Rem celsbern 06/22/10 - removing mention of paths in prompts
Rem celsbern 06/02/10 - converted to use impdp.
Rem glyon 06/27/07 - grant CWM_USER role to SH user
Rem bmccarth 05/29/07 - need territory american on external table
Rem pabingha 02/26/07 - LRG 2871657 use dimension_exceptions
Rem cbauwens 05/02/05 - bug4054905 Date & Time format
Rem cbauwens 04/19/05 - fix privs for SH and BI
Rem cbauwens 12/03/04 - add call to olp_v3.sql for cube metadata
Rem cbauwens 10/29/04 - modifying privs after deprecation of connect
Rem cbauwens 07/26/04 - remove stylesheet tab
Rem rsahani 09/08/04 - privileges granted must be same
Rem as granted when creating schema
Rem jcjeon 03/30/04 - fix lrg1628995
Rem huzhao 01/28/04 - validate certain AQ within IX schema after TTS import
Rem cbauwens 11/18/03 - lrg1582814
Rem cbauwens 08/21/03 - OMF support
Rem cbauwens 08/05/03 - profits view
Rem cbauwens 08/05/03 - company_id
Rem cbauwens 06/19/03 - bug_2878871
Rem cbauwens 06/18/03 - bug_2878871
Rem ahunold 03/27/03 - Objects not transported: lrg 1348159
Rem ahunold 03/01/03 - Bug 2828348
Rem ahunold 02/10/03 - grants AFTER mk_dir, TS ver. query
Rem ahunold 01/27/03 - RMAN restore
Rem ahunold 01/16/03 - CONNECT errors
Rem ahunold 12/11/02 - password variables, line continuation
Rem ahunold 09/30/02 - procedures, directories
Rem ahunold 09/25/02 - imp logfile
Rem ahunold 09/18/02 - Created
Rem
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 80
SET TRIMSPOOL ON
SET TAB OFF
SET PAGESIZE 999
SET ECHO OFF
SET CONCAT '.'
SET SHOWMODE OFF
PROMPT
PROMPT specify password for SYS as parameter 1:
DEFINE password_sys = &1
PROMPT
PROMPT specify password for HR as parameter 2:
DEFINE password_hr = &2
PROMPT
PROMPT specify password for OE as parameter 3:
DEFINE password_oe = &3
PROMPT
PROMPT specify password for PM as parameter 4:
DEFINE password_pm = &4
PROMPT
PROMPT specify password for IX as parameter 5:
DEFINE password_ix = &5
PROMPT
PROMPT specify password for SH as parameter 6:
DEFINE password_sh = &6
PROMPT
PROMPT specify password for BI as parameter 7:
DEFINE password_bi = &7
PROMPT
PROMPT specify INPUT metadata import file as parameter 8:
DEFINE imp_file = &8
PROMPT
PROMPT specify INPUT database backup file for tablespace EXAMPLE as parameter 9:
DEFINE data_file_backup = &9
PROMPT
PROMPT specify OUTPUT database file for tablespace EXAMPLE as parameter 10:
DEFINE data_file_name = &10
PROMPT
PROMPT specify OUTPUT log directory as parameter 11:
DEFINE log_path = &11
PROMPT
PROMPT specify OUTPUT dump file directory as parameter 12:
DEFINE dump_path = &12
PROMPT
PROMPT specify oe data file directory for loading oe data as parameter 13:
DEFINE oe_data_path = &13
PROMPT
PROMPT Sample Schemas are being plugged in ...
PROMPT
DEFINE vrs = v3
SPOOL &log_path.mkplug_&[email protected]
--
-- Running the instantiated mk_dir.sql, thus connecting
-- the DIRECTORY objects with the appropriate file system
-- paths on this specific system
--
CONNECT sys/&&password_sys AS SYSDBA;
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
--
-- Creating users and granting system privileges
--
CREATE USER hr IDENTIFIED BY &&password_hr ;
CREATE USER oe IDENTIFIED BY &&password_oe ;
CREATE USER ix IDENTIFIED BY &&password_ix ;
CREATE USER sh IDENTIFIED BY &&password_sh ;
CREATE USER pm IDENTIFIED BY &&password_pm ;
CREATE USER bi IDENTIFIED BY &&password_bi ;
@__SUB__CWD__/mk_dir
GRANT CREATE SESSION TO hr;
GRANT ALTER SESSION TO hr;
GRANT CREATE DATABASE LINK TO hr;
GRANT CREATE SEQUENCE TO hr;
GRANT CREATE SYNONYM TO hr;
GRANT CREATE VIEW TO hr;
GRANT RESOURCE , UNLIMITED TABLESPACE TO hr;
GRANT execute ON sys.dbms_stats TO hr;
GRANT CREATE SESSION TO oe;
GRANT CREATE DATABASE LINK TO oe;
GRANT CREATE SYNONYM TO oe;
GRANT CREATE VIEW TO oe;
GRANT RESOURCE , UNLIMITED TABLESPACE TO oe;
GRANT CREATE MATERIALIZED VIEW TO oe;
GRANT QUERY REWRITE TO oe;
GRANT execute ON sys.dbms_stats TO oe;
grant create trigger TO oe;
grant xdbadmin To oe;
grant create any directory TO oe;
GRANT drop any directory TO oe;
GRANT alter session TO oe;
GRANT CONNECT TO pm;
GRANT RESOURCE , UNLIMITED TABLESPACE TO pm;
GRANT execute ON sys.dbms_stats TO pm;
GRANT READ ON DIRECTORY media_dir TO pm;
GRANT CONNECT TO ix;
GRANT RESOURCE , UNLIMITED TABLESPACE TO ix;
GRANT aq_administrator_role TO ix;
GRANT aq_user_role TO ix;
GRANT ALTER SESSION TO ix;
GRANT CREATE CLUSTER TO ix;
GRANT CREATE DATABASE LINK TO ix;
GRANT CREATE SEQUENCE TO ix;
GRANT CREATE SESSION TO ix;
GRANT CREATE SYNONYM TO ix;
GRANT CREATE TABLE TO ix;
GRANT CREATE VIEW TO ix;
GRANT CREATE CLUSTER TO ix;
GRANT CREATE INDEXTYPE TO ix;
GRANT CREATE OPERATOR TO ix;
GRANT CREATE PROCEDURE TO ix;
GRANT CREATE SEQUENCE TO ix;
GRANT CREATE TABLE TO ix;
GRANT CREATE TRIGGER TO ix;
GRANT CREATE TYPE TO ix;
GRANT CREATE SESSION TO ix;
GRANT CONNECT, RESOURCE, UNLIMITED TABLESPACE, SELECT_CATALOG_ROLE TO ix;
GRANT EXECUTE ON sys.dbms_stats TO ix;
GRANT EXECUTE ON DBMS_AQ TO ix;
GRANT EXECUTE ON DBMS_AQADM TO ix;
GRANT EXECUTE ON DBMS_APPLY_ADM TO ix;
GRANT EXECUTE ON DBMS_CAPTURE_ADM TO ix;
GRANT EXECUTE ON DBMS_FLASHBACK TO ix;
GRANT EXECUTE ON DBMS_PROPAGATION_ADM TO ix;
GRANT EXECUTE ON DBMS_STREAMS_ADM TO ix;
GRANT SELECT ANY DICTIONARY TO ix;
EXECUTE DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE( -
privilege => DBMS_RULE_ADM.CREATE_RULE_SET_OBJ, -
grantee => 'ix', -
grant_option => FALSE);
EXECUTE DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE( -
privilege => DBMS_RULE_ADM.CREATE_RULE_OBJ, -
grantee => 'ix', -
grant_option => FALSE);
GRANT CREATE SESSION TO sh;
GRANT CREATE TABLE TO sh;
GRANT CREATE VIEW TO sh;
GRANT CREATE CLUSTER TO sh;
GRANT ALTER SESSION TO sh;
GRANT CREATE SEQUENCE TO sh;
GRANT CREATE SYNONYM TO sh;
GRANT CREATE DATABASE LINK TO sh;
GRANT CREATE DIMENSION TO sh;
GRANT QUERY REWRITE TO sh;
GRANT CREATE MATERIALIZED VIEW TO sh;
GRANT CREATE VIEW TO sh;
GRANT RESOURCE , UNLIMITED TABLESPACE TO sh;
GRANT select_catalog_role TO sh;
GRANT execute ON sys.dbms_stats TO sh;
rem ALTER USER sh GRANT CONNECT THROUGH olapsvr;
GRANT CREATE SESSION TO bi;
GRANT CREATE TABLE TO bi;
GRANT CREATE VIEW TO bi;
GRANT CREATE CLUSTER TO bi;
GRANT ALTER SESSION TO bi;
GRANT CREATE SEQUENCE TO bi;
GRANT CREATE SYNONYM TO bi;
GRANT CREATE DATABASE LINK TO bi;
GRANT RESOURCE , UNLIMITED TABLESPACE TO bi;
--
-- Restoring database file backup
-- (Using RMAN works in OMF, OCFS, raw devices and in normal file systems)
--
set echo off;
set serveroutput on;
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
variable new_datafile varchar2(512)
declare
done boolean;
v_db_create_file_dest VARCHAR2(512);
devicename varchar2(255);
data_file_id number;
rec_id number;
stamp number;
resetlogs_change number;
creation_change number;
checkpoint_change number;
blksize number;
omfname varchar2(512);
real_file_name varchar2(512);
v_is_pdb number;
begin
dbms_output.put_line(' ');
dbms_output.put_line(' Allocating device.... ');
dbms_output.put_line(' Specifying datafiles... ');
devicename := dbms_backup_restore.deviceAllocate;
dbms_output.put_line(' Specifing datafiles... ');
/*************************************************************************/
/* Note that the 'select 10' statement below here is a workaround for */
/* INSTALL and pdb databases. */
/* If you receive an error about not being able to find a tablespace */
/* the file_id needs to change from 10 to something else. */
/*************************************************************************/
select 10 into data_file_id from dual;
SELECT value INTO v_db_create_file_dest FROM v$parameter WHERE name ='db_create_file_dest';
IF v_db_create_file_dest IS NOT NULL
THEN
dbms_backup_restore.restoreSetDataFile;
dbms_backup_restore.getOMFFileName('EXAMPLE',omfname);
dbms_backup_restore.restoreDataFileTo(data_file_id, omfname, 0,'EXAMPLE');
ELSE
dbms_backup_restore.restoreSetDataFile;
dbms_backup_restore.restoreDataFileTo(data_file_id,'&data_file_name');
END IF;
dbms_output.put_line(' Restoring ... ');
dbms_backup_restore.restoreBackupPiece('&dump_path'||'&data_file_backup', done);
SELECT max(recid) INTO rec_id FROM v$datafile_copy;
-- Now get the real file name. It could be also OMF filename
SELECT name, stamp, resetlogs_change#, creation_change#, checkpoint_change#,block_size
INTO real_file_name, stamp,resetlogs_change, creation_change, checkpoint_change, blksize
FROM V$DATAFILE_COPY
WHERE recid = rec_id and rfile# = data_file_id;
-- Set the bindvariable to the real filename
:new_datafile := real_file_name;
-- Uncatalog the file from V$DATAFILE_COPY. This important.
dbms_backup_restore.deleteDataFileCopy(recid => rec_id,
stamp => stamp,
fname => real_file_name,
dfnumber => data_file_id,
resetlogs_change => resetlogs_change,
creation_change => creation_change,
checkpoint_change => checkpoint_change,
blksize => blksize,
no_delete => 1,
force => 1);
if done then
dbms_output.put_line(' Restore done.');
else
dbms_output.put_line(' ORA-XXXX: Restore failed ');
end if;
end;
/
rem Transfer the value from the bind variable to the substitution variable
rem so it can be used in the imp command
col subnew_datafile new_value datafile noprint
select :new_datafile subnew_datafile from dual;
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
-- create the 'SS_IMPEXP_DIR' directory object for imp/exp
-- this will be explicitly dropped at the end.
create or replace directory SS_IMPEXP_DIR as '&dump_path';
grant read,write on directory SS_IMPEXP_DIR to public;
create or replace directory SS_LOGPATH_DIR as '&log_path';
grant read,write on directory SS_LOGPATH_DIR to public;
--
-- Importing the metadata and plugging in the tablespace at the same
-- time, using the restored database file
--
-- When importing use filename got after restore is finished
host impdp "'sys/&&password_sys AS SYSDBA'" directory=SS_IMPEXP_DIR logfile=SS_LOGPATH_DIR:tts_example_imp.log dumpfile=&imp_file transport_datafiles='&datafile' EXCLUDE=trigger,functional_index,index_statistics silent=banner
CONNECT sys/&&password_sys AS SYSDBA;
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
ALTER TABLESPACE example READ WRITE;
COLUMN tablespace_name FORMAT A15
COLUMN file_name FORMAT A46
SELECT tablespace_name, file_name, status
FROM dba_data_files
ORDER BY file_id;
REM
REM Now we rebuild the objects that cannot
REM be part of a transportable tablespace set
REM ==========================================
REM
PROMPT
PROMPT Creating sequences, views, procedures and objects privileges for HR ...
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
CONNECT hr/&&password_hr;
--
-- Sequences
--
CREATE SEQUENCE locations_seq
START WITH 3300
INCREMENT BY 100
MAXVALUE 9900
NOCACHE
NOCYCLE;
CREATE SEQUENCE departments_seq
START WITH 280
INCREMENT BY 10
MAXVALUE 9990
NOCACHE
NOCYCLE;
CREATE SEQUENCE employees_seq
START WITH 207
INCREMENT BY 1
NOCACHE
NOCYCLE;
--
-- Views
--
CREATE OR REPLACE VIEW emp_details_view
(employee_id,
job_id,
manager_id,
department_id,
location_id,
country_id,
first_name,
last_name,
salary,
commission_pct,
department_name,
job_title,
city,
state_province,
country_name,
region_name)
AS SELECT
e.employee_id,
e.job_id,
e.manager_id,
e.department_id,
d.location_id,
l.country_id,
e.first_name,
e.last_name,
e.salary,
e.commission_pct,
d.department_name,
j.job_title,
l.city,
l.state_province,
c.country_name,
r.region_name
FROM
employees e,
departments d,
jobs j,
locations l,
countries c,
regions r
WHERE e.department_id = d.department_id
AND d.location_id = l.location_id
AND l.country_id = c.country_id
AND c.region_id = r.region_id
AND j.job_id = e.job_id
WITH READ ONLY;
--
-- Rebuilding procedural objects
--
@__SUB__CWD__/human_resources/hr_code
-- rebuild OE by dropping and recreating
CONNECT sys/&&password_sys AS SYSDBA;
drop user oe cascade;
CREATE USER oe IDENTIFIED BY &&password_oe ;
GRANT CREATE SESSION TO oe;
GRANT CREATE DATABASE LINK TO oe;
GRANT CREATE SYNONYM TO oe;
GRANT CREATE VIEW TO oe;
GRANT RESOURCE,UNLIMITED TABLESPACE TO oe;
GRANT CREATE MATERIALIZED VIEW TO oe;
GRANT QUERY REWRITE TO oe;
GRANT execute ON sys.dbms_stats to oe;
grant create trigger TO oe;
grant xdbadmin To oe;
grant create any directory TO oe;
GRANT drop any directory TO oe;
GRANT alter session TO oe;
@__SUB__CWD__/order_entry/oe_main.sql &&password_oe EXAMPLE TEMP &&password_hr &&password_sys &&oe_data_path &&log_path &vrs
--
-- oe_main.sql creates and closes it's own log file. start part2 of mkplug here
--
-- the '.' is the sql concat charater - that's why there are 2 '.' before log
SPOOL &log_path.mkplug_p2_&vrs..log
--
-- Object privileges
--
connect hr/&&password_hr;
GRANT REFERENCES, SELECT ON employees TO oe;
GRANT REFERENCES, SELECT ON countries TO oe;
GRANT REFERENCES, SELECT ON locations TO oe;
GRANT SELECT ON jobs TO oe;
GRANT SELECT ON job_history TO oe;
GRANT SELECT ON departments TO oe;
PROMPT
PROMPT Creating synonyms, sequences, views and functions for OE ...
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
CONNECT oe/&&password_oe;
--
-- Create cross-schema synonyms
--
GRANT SELECT ON bombay_inventory TO bi;
GRANT SELECT ON customers TO bi;
GRANT SELECT ON inventories TO bi;
GRANT SELECT ON orders TO bi;
GRANT SELECT ON order_items TO bi;
GRANT SELECT ON products TO bi;
GRANT SELECT ON product_descriptions TO bi;
GRANT SELECT ON product_information TO bi;
GRANT SELECT ON product_prices TO bi;
GRANT SELECT ON promotions TO bi;
GRANT SELECT ON sydney_inventory TO bi;
GRANT SELECT ON toronto_inventory TO bi;
GRANT SELECT ON warehouses TO bi;
GRANT REFERENCES, SELECT ON product_information TO pm;
GRANT SELECT ON order_items TO pm;
GRANT SELECT ON orders TO pm;
GRANT SELECT ON product_descriptions TO pm;
GRANT SELECT ON inventories TO pm;
GRANT SELECT ON customers TO pm;
GRANT SELECT ON warehouses TO pm;
PROMPT
PROMPT Creating dimensions, materialized views, external table and object privileges for SH ...
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
CONNECT sh/&&password_sh;
CREATE DIMENSION customers_dim
LEVEL customer IS (customers.cust_id)
LEVEL city IS (customers.cust_city_id)
LEVEL state IS (customers.cust_state_province_id)
LEVEL country IS (countries.country_id)
LEVEL subregion IS (countries.country_subregion_id)
LEVEL region IS (countries.country_region_id)
LEVEL geog_total IS (countries.country_total_id)
LEVEL cust_total IS (customers.cust_total_id)
HIERARCHY cust_rollup (customer CHILD OF
city CHILD OF
state CHILD OF
cust_total)
HIERARCHY geog_rollup (customer CHILD OF
city CHILD OF
state CHILD OF
country CHILD OF
subregion CHILD OF
region CHILD OF
geog_total
JOIN KEY (customers.country_id) REFERENCES country)
ATTRIBUTE customer DETERMINES
(cust_first_name, cust_last_name, cust_gender,
cust_marital_status, cust_year_of_birth,
cust_income_level, cust_credit_limit,
cust_street_address, cust_postal_code,
cust_main_phone_number, cust_email)
ATTRIBUTE city DETERMINES (cust_city)
ATTRIBUTE state DETERMINES (cust_state_province)
ATTRIBUTE country DETERMINES (countries.country_name,countries.country_iso_code)
ATTRIBUTE subregion DETERMINES (countries.country_subregion)
ATTRIBUTE region DETERMINES (countries.country_region)
ATTRIBUTE geog_total DETERMINES (countries.country_total)
ATTRIBUTE cust_total DETERMINES (customers.cust_total);
COMMIT;
CREATE DIMENSION products_dim
LEVEL product IS (products.prod_id)
LEVEL subcategory IS (products.prod_subcategory_id)
LEVEL category IS (products.prod_category_id)
LEVEL prod_total IS (products.prod_total_id)
HIERARCHY prod_rollup (product CHILD OF
subcategory CHILD OF
category CHILD OF
prod_total)
ATTRIBUTE product DETERMINES
(products.prod_name, products.prod_desc,
prod_weight_class, prod_unit_of_measure,
prod_pack_size,prod_status, prod_list_price, prod_min_price)
ATTRIBUTE subcategory DETERMINES
(prod_subcategory, prod_subcategory_desc)
ATTRIBUTE category DETERMINES
(prod_category, prod_category_desc)
ATTRIBUTE prod_total DETERMINES
(prod_total);
CREATE DIMENSION times_dim
LEVEL day IS TIMES.TIME_ID
LEVEL month IS TIMES.CALENDAR_MONTH_ID
LEVEL quarter IS TIMES.CALENDAR_QUARTER_ID
LEVEL year IS TIMES.CALENDAR_YEAR_ID
LEVEL fis_week IS TIMES.WEEK_ENDING_DAY_ID
LEVEL fis_month IS TIMES.FISCAL_MONTH_ID
LEVEL fis_quarter IS TIMES.FISCAL_QUARTER_ID
LEVEL fis_year IS TIMES.FISCAL_YEAR_ID
HIERARCHY cal_rollup (day CHILD OF
month CHILD OF
quarter CHILD OF
year)
HIERARCHY fis_rollup (day CHILD OF
fis_week CHILD OF
fis_month CHILD OF
fis_quarter CHILD OF
fis_year)
ATTRIBUTE day DETERMINES
(day_number_in_week, day_name, day_number_in_month,
calendar_week_number)
ATTRIBUTE month DETERMINES
(calendar_month_desc,
calendar_month_number, calendar_month_name,
days_in_cal_month, end_of_cal_month)
ATTRIBUTE quarter DETERMINES
(calendar_quarter_desc,
calendar_quarter_number,days_in_cal_quarter,
end_of_cal_quarter)
ATTRIBUTE year DETERMINES
(calendar_year,
days_in_cal_year, end_of_cal_year)
ATTRIBUTE fis_week DETERMINES
(week_ending_day,
fiscal_week_number)
ATTRIBUTE fis_month DETERMINES
(fiscal_month_desc, fiscal_month_number, fiscal_month_name,
days_in_fis_month, end_of_fis_month)
ATTRIBUTE fis_quarter DETERMINES
(fiscal_quarter_desc,
fiscal_quarter_number, days_in_fis_quarter,
end_of_fis_quarter)
ATTRIBUTE fis_year DETERMINES
(fiscal_year,
days_in_fis_year, end_of_fis_year);
CREATE DIMENSION channels_dim
LEVEL channel IS (channels.channel_id)
LEVEL channel_class IS (channels.channel_class_id)
LEVEL channel_total IS (channels.channel_total_id)
HIERARCHY channel_rollup (channel CHILD OF
channel_class CHILD OF
channel_total)
ATTRIBUTE channel DETERMINES (channel_desc)
ATTRIBUTE channel_class DETERMINES (channel_class)
ATTRIBUTE channel_total DETERMINES (channel_total);
CREATE DIMENSION promotions_dim
LEVEL promo IS (promotions.promo_id)
LEVEL subcategory IS (promotions.promo_subcategory_id)
LEVEL category IS (promotions.promo_category_id)
LEVEL promo_total IS (promotions.promo_total_id)
HIERARCHY promo_rollup (promo CHILD OF
subcategory CHILD OF
category CHILD OF
promo_total)
ATTRIBUTE promo DETERMINES
(promo_name, promo_cost,
promo_begin_date, promo_end_date)
ATTRIBUTE subcategory DETERMINES (promo_subcategory)
ATTRIBUTE category DETERMINES (promo_category)
ATTRIBUTE promo_total DETERMINES (promo_total);
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
CREATE OR REPLACE VIEW profits
AS SELECT
s.channel_id,
s.cust_id,
s.prod_id,
s.promo_id,
s.time_id,
c.unit_cost,
c.unit_price,
s.amount_sold,
s.quantity_sold,
c.unit_cost * s.quantity_sold TOTAL_COST
FROM costs c, sales s
WHERE c.prod_id = s.prod_id
AND c.time_id = s.time_id
AND c.channel_id = s.channel_id
AND c.promo_id = s.promo_id;
--
-- External Table
--
CREATE TABLE sales_transactions_ext
( PROD_ID NUMBER,
CUST_ID NUMBER,
TIME_ID DATE,
CHANNEL_ID NUMBER,
PROMO_ID NUMBER,
QUANTITY_SOLD NUMBER,
AMOUNT_SOLD NUMBER(10,2),
UNIT_COST NUMBER(10,2),
UNIT_PRICE NUMBER(10,2)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY data_file_dir
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
TERRITORY AMERICA
BADFILE log_file_dir:'ext_1v3.bad'
LOGFILE log_file_dir:'ext_1v3.log'
FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY '^' LDRTRIM
( PROD_ID ,
CUST_ID ,
TIME_ID DATE(10) "YYYY-MM-DD",
CHANNEL_ID ,
PROMO_ID ,
QUANTITY_SOLD ,
AMOUNT_SOLD ,
UNIT_COST ,
UNIT_PRICE
)
)
LOCATION
('sale1v3.dat')
)
REJECT LIMIT 100;
PROMPT
PROMPT Creating OLAP metadata ...
--
-- Object Privileges
--
GRANT SELECT ON channels TO bi;
GRANT SELECT ON countries TO bi;
GRANT SELECT ON times TO bi;
GRANT SELECT ON costs TO bi;
GRANT SELECT ON customers TO bi;
GRANT SELECT ON products TO bi;
GRANT SELECT ON promotions TO bi;
GRANT SELECT ON sales TO bi;
GRANT SELECT ON times TO bi;
GRANT SELECT ON cal_month_sales_mv TO bi;
GRANT SELECT ON sh.fweek_pscat_sales_mv TO bi;
PROMPT
PROMPT Creating views, synonyms for BI ...
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
@__SUB__CWD__/bus_intelligence/bi_views.sql &&password_bi
--
-- set up extra contraints in the PM schema
connect pm/&&password_pm;
ALTER TABLE print_media
ADD ( CONSTRAINT printmedia_fk
FOREIGN KEY (product_id)
REFERENCES oe.product_information(product_id) ) ;
ALTER TABLE online_media
ADD ( CONSTRAINT loc_c_id_fk
FOREIGN KEY (product_id)
REFERENCES oe.product_information(product_id) ) ;
connect sys/&&password_sys as sysdba
-- reanalyze everything so that we're all up to date
connect oe/&&password_oe;
@__SUB__CWD__/order_entry/oe_analz
connect pm/&&password_pm;
@__SUB__CWD__/product_media/pm_analz
connect hr/&&password_hr;
@__SUB__CWD__/human_resources/hr_analz
connect sh/&&password_sh
@__SUB__CWD__/sales_history/sh_analz
REM Validate certain AQ within IX schema after TTS import
CONNECT sys/&&password_sys AS SYSDBA;
EXECUTE dbms_aqadm_sys.validate_Queue('IX', 'AQ$_ORDERS_QUEUETABLE_E');
EXECUTE dbms_aqadm_sys.validate_Queue('IX', 'AQ$_STREAMS_QUEUE_TABLE_E');
EXECUTE dbms_aqadm_sys.validate_Queue('IX', 'ORDERS_QUEUE');
EXECUTE dbms_aqadm_sys.validate_Queue('IX', 'STREAMS_QUEUE');
-- renanalyze ix
EXECUTE dbms_stats.gather_schema_stats('IX');
-- clean up the directory object now that we're done with it.
drop directory SS_IMPEXP_DIR;
drop directory SS_LOGPATH_DIR;
-- fix up the coe_% public synonyms
CREATE OR REPLACE PUBLIC SYNONYM COE_CONFIGURATION FOR COE_CONFIGURATION;
CREATE OR REPLACE PUBLIC SYNONYM COE_NAMESPACES FOR COE_NAMESPACES;
CREATE OR REPLACE PUBLIC SYNONYM COE_DOM_HELPER FOR COE_DOM_HELPER;
CREATE OR REPLACE PUBLIC SYNONYM COE_UTILITIES FOR COE_UTILITIES;
CREATE OR REPLACE PUBLIC SYNONYM COE_TOOLS FOR COE_TOOLS;
-- check for invalid objects
select count(*) , ' Invalid Objects' from dba_objects where status = 'INVALID';
select owner,object_name, object_type
from dba_objects where status = 'INVALID';
PROMPT
PROMPT mkplug.sql DONE
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;