|
本帖最后由 botang 于 2017-5-7 19:39 编辑
第一阶段OCM Exam Preparation(8-10):
s0.sql:
- CREATE DATABASE PROD
- USER SYS IDENTIFIED BY oracle
- USER SYSTEM IDENTIFIED BY oracle
- LOGFILE GROUP 1 ('/u01/app/oracle/oradata/PROD/Disk1/redo01.log') SIZE 100M,
- GROUP 2 ('/u01/app/oracle/oradata/PROD/Disk2/redo02.log') SIZE 100M,
- GROUP 3 ('/u01/app/oracle/oradata/PROD/Disk3/redo03.log') SIZE 100M
- MAXLOGFILES 50
- MAXLOGMEMBERS 5
- MAXLOGHISTORY 1
- MAXDATAFILES 100
- MAXINSTANCES 1
- CHARACTER SET AL32UTF8
- NATIONAL CHARACTER SET AL16UTF16
- DATAFILE '/u01/app/oracle/oradata/PROD/Disk1/system01.dbf' SIZE 700M REUSE autoextend on
- EXTENT MANAGEMENT LOCAL
- SYSAUX DATAFILE '/u01/app/oracle/oradata/PROD/Disk2/sysaux01.dbf' SIZE 500M REUSE autoextend on
- DEFAULT TABLESPACE users DATAFILE '/u01/app/oracle/oradata/PROD/Disk4/users01.dbf' size 30M autoextend on
- DEFAULT TEMPORARY TABLESPACE temp
- TEMPFILE '/u01/app/oracle/oradata/PROD/Disk5/temp01.dbf'
- SIZE 50M REUSE autoextend on
- UNDO TABLESPACE undotbs1
- DATAFILE '/u01/app/oracle/oradata/PROD/Disk3/undotbs1.dbf'
- SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
复制代码 s2.sql:
- create or replace procedure proc_s2
- is
- begin
- for rec in ( select index_name from dba_indexes where owner='HR' and index_type <> 'IOT - TOP')
- loop
- execute immediate 'alter index hr.'||rec.index_name||' rebuild online';
- end loop;
- end;
- /
复制代码 s4.sql:
- set serveroutput on
- declare
- v_1 varchar2(100);
- begin
- dbms_advisor.TUNE_MVIEW( TASK_NAME => v_1 ,
- MV_CREATE_STMT=>'create materialized view sh.prod_mv refresh fast enable query rewrite as SELECT time_id,prod_subcategory,SUM(unit_cost) ucost FROM sh.costs c,sh.products p where c.prod_id=p.prod_id GROUP BY time_id,prod_subcategory');
- dbms_output.put_line(dbms_advisor.GET_TASK_SCRIPT(v_1)) ;
- end;
- /
复制代码 s41.sql:
- CREATE
- MATERIALIZED VIEW LOG ON
- "SH"."COSTS"
- WITH ROWID,
- SEQUENCE("PROD_ID","TIME_ID","UNIT_COST")
- INCLUDING NEW VALUES;
- CREATE
- MATERIALIZED VIEW LOG ON
- "SH"."PRODUCTS"
- WITH ROWID,
- SEQUENCE("PROD_ID","PROD_SUBCATEGORY")
- INCLUDING NEW VALUES;
- CREATE
- MATERIALIZED VIEW SH.PROD_MV
- REFRESH FAST WITH ROWID
- ENABLE QUERY
- REWRITE
- AS SELECT SH.PRODUCTS.PROD_SUBCATEGORY C1, SH.COSTS.TIME_ID C2,
- SUM("SH"."COSTS"."UNIT_COST")
- M1, COUNT("SH"."COSTS"."UNIT_COST") M2,
- COUNT(*) M3 FROM SH.PRODUCTS,
- SH.COSTS WHERE SH.COSTS.PROD_ID =
- SH.PRODUCTS.PROD_ID GROUP BY SH.PRODUCTS.PROD_SUBCATEGORY,
- SH.COSTS.TIME_ID;
复制代码 s42.sql:
- select employee_id, first_name, last_name, phone_number, salary
- from employees@dblink1;
复制代码 s43.sql:
- create table sh.prod_master
- (
- PROD_ID number,
- CUST_ID number,
- TIME_ID date,
- CHANNEL_ID varchar2(10),
- PROMO_ID number,
- QUANTITY_SOLD number,
- AMOUNT_SOLD number(8,2)
- );
复制代码 s431.txt:
- sqlldr sh/sh control=myprod_master.ctl data=prod_master.dat log=/home/oracle/s44.sql external_table=GENERATE_ONLY
复制代码 s44.sql:
- drop table sh.PROD_MASTER;
- CREATE TABLE sh.PROD_MASTER
- (
- "PROD_ID" NUMBER,
- "CUST_ID" NUMBER,
- "TIME_ID" DATE,
- "CHANNEL_ID" VARCHAR2(10),
- "PROMO_ID" NUMBER,
- "QUANTITY_SOLD" NUMBER,
- "AMOUNT_SOLD" NUMBER(8,2)
- )
- ORGANIZATION external
- (
- TYPE oracle_loader
- DEFAULT DIRECTORY DIR1
- ACCESS PARAMETERS
- (
- RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
- BADFILE 'DIR1':'prod_master.bad'
- LOGFILE 'prod_master.log'
- READSIZE 1048576
- FIELDS TERMINATED BY "|" LDRTRIM
- MISSING FIELD VALUES ARE NULL
- REJECT ROWS WITH ALL NULL FIELDS
- (
- "PROD_ID" CHAR(255)
- TERMINATED BY "|",
- "CUST_ID" CHAR(255)
- TERMINATED BY "|",
- "TIME_ID" CHAR(255)
- TERMINATED BY "|"
- DATE_FORMAT DATE MASK "DD-MON-YYYY",
- "CHANNEL_ID" CHAR(255)
- TERMINATED BY "|",
- "PROMO_ID" CHAR(255)
- TERMINATED BY "|",
- "QUANTITY_SOLD" CHAR(255)
- TERMINATED BY "|",
- "AMOUNT_SOLD" CHAR(255)
- TERMINATED BY "|"
- )
- )
- location
- (
- 'prod_master.dat'
- )
- )REJECT LIMIT UNLIMITED;
复制代码 s45.sql:
- create table sh.countries_ext
- organization external
- (
- type oracle_datapump
- default directory dir1
- location ( 'countries_ext.dmp' )
- )
- reject limit unlimited
- as
- select country_id, country_name,country_region
- from sh.countries;
复制代码 s46.sql:
- create table system.countries_ext
- ( country_id NUMBER , country_name VARCHAR2(40) ,country_region VARCHAR2(20) )
- organization external
- (
- type oracle_datapump
- default directory dir1
- location ( 'countries_ext.dmp' )
- )
- reject limit unlimited;
复制代码
|
|