|
第一阶段OCM Exam Preparation(11-13):
s5.sql:
- create table hr.MAGAZINE_ARTICLES(
- AUTHOR VARCHAR2(30),
- ARTICLE_NAME VARCHAR2(50),
- ARTICLE_DATE DATE,
- ARTICLE_DATA CLOB )
- tablespace users lob(ARTICLE_DATA) store as (
- tablespace lob_data chunk 16k storage (initial 2M next 2M)
- nocache disable storage in row);
复制代码 s52.sql:
- create table hr.ORACLE9I_REFERENCES(
- ORACLE9I_ARTICLE ROWID,
- INSERT_TIME TIMESTAMP WITH LOCAL TIME ZONE);
复制代码 s53.sql:
- insert into hr.ORACLE9I_REFERENCES
- select rowid , scn_to_timestamp(ora_rowscn) from hr.MAGAZINE_ARTICLES where instr(AUTHOR||ARTICLE_NAME||ARTICLE_DATE||ARTICLE_DATA,'Oracle9i',1,3)>0;
- commit;
复制代码 s54.sql:
- create tablespace DATA01 datafile '/u01/app/oracle/oradata/PROD/Disk1/DATA01.dbf' size 250M uniform size 4M blocksize 16K;
- create tablespace DATA02 datafile '/u01/app/oracle/oradata/PROD/Disk2/DATA02.dbf' size 250M uniform size 4M blocksize 16K;
- create tablespace DATA03 datafile '/u01/app/oracle/oradata/PROD/Disk3/DATA03.dbf' size 250M uniform size 4M blocksize 16K;
- create tablespace DATA04 datafile '/u01/app/oracle/oradata/PROD/Disk4/DATA04.dbf' size 250M uniform size 4M blocksize 16K;
- create tablespace DATA05 datafile '/u01/app/oracle/oradata/PROD/Disk5/DATA05.dbf' size 250M uniform size 4M blocksize 16K;
复制代码 s55.sql:
- create table sh.sales_history
- partition by range(sdate)
- (partition p1 values less than (to_date('1999-01-01','YYYY-MM-DD')) tablespace data01 ,
- partition p2 values less than (to_date('2000-01-01','YYYY-MM-DD')) tablespace data02,
- partition p3 values less than (to_date('2001-01-01','YYYY-MM-DD')) tablespace data03,
- partition p4 values less than (to_date('2002-01-01','YYYY-MM-DD')) tablespace data04,
- partition p5 values less than (to_date('2003-01-01','YYYY-MM-DD')) tablespace data05)
- as select * from oltp_user.sales where 1=2;
复制代码 s56.sql:
- create unique index sh.SALES_HISTORY_PK
- on sh.SALES_HISTORY(SALES_ID)
- global partition by hash(SALES_ID)
- (
- partition p1 tablespace INDX,
- partition p2 tablespace INDX,
- partition p3 tablespace INDX,
- partition p4 tablespace INDX
- )
- parallel 4;
复制代码 s57.sql:
- create index sh.SALES_HISTORY_DATE_IDX on
- sh.SALES_HISTORY(sdate) local;
复制代码 s58.sql:
- select text from dba_source where name='DBMS_FGA';
- begin
- dbms_fga.drop_policy(
- OBJECT_SCHEMA =>'HR',
- OBJECT_NAME=>'EMPLOYEES',
- POLICY_NAME=>'POLICY1'
- );
- dbms_fga.add_policy(
- OBJECT_SCHEMA =>'HR',
- OBJECT_NAME=>'EMPLOYEES',
- POLICY_NAME=>'POLICY1',
- AUDIT_CONDITION=>'SALARY is not null or COMMISSION_PCT is not null',
- AUDIT_COLUMN=>'SALARY,COMMISSION_PCT',
- STATEMENT_TYPES=>'SELECT'
- );
- end;
- /
复制代码 s59.sql:
- create table hr.ORIGINAL_SALARY as
- select employee_id, commission_pct, salary
- from hr.employees ;
复制代码 s6.sql:
- BEGIN
- dbms_resource_manager.clear_pending_area();
- dbms_resource_manager.create_pending_area();
- dbms_resource_manager.create_plan( 'WEEKDAYS', 'WEEKDAYS',CPU_MTH=>'RATIO');
- dbms_resource_manager.create_plan_directive(
- plan => 'WEEKDAYS',
- group_or_subplan => 'DSS',
- comment => '',
- cpu_p1 => 30, cpu_p2 => NULL, cpu_p3 => NULL, cpu_p4 => NULL,
- cpu_p5 => NULL, cpu_p6 => NULL, cpu_p7 => NULL, cpu_p8 => NULL,
- parallel_degree_limit_p1 => NULL,
- active_sess_pool_p1 => NULL,
- queueing_p1 => NULL,
- switch_group => '',
- switch_time => NULL,
- switch_estimate => false,
- max_est_exec_time => NULL,
- undo_pool => NULL,
- max_idle_time => NULL,
- max_idle_blocker_time => NULL,
- switch_time_in_call => NULL
- );
- dbms_resource_manager.create_plan_directive(
- plan => 'WEEKDAYS',
- group_or_subplan => 'OLTP',
- comment => '',
- cpu_p1 => 50, cpu_p2 => NULL, cpu_p3 => NULL, cpu_p4 => NULL,
- cpu_p5 => NULL, cpu_p6 => NULL, cpu_p7 => NULL, cpu_p8 => NULL,
- parallel_degree_limit_p1 => NULL,
- active_sess_pool_p1 => NULL,
- queueing_p1 => NULL,
- switch_group => '',
- switch_time => NULL,
- switch_estimate => false,
- max_est_exec_time => NULL,
- undo_pool => NULL,
- max_idle_time => NULL,
- max_idle_blocker_time => NULL,
- switch_time_in_call => NULL
- );
- dbms_resource_manager.create_plan_directive(
- plan => 'WEEKDAYS',
- group_or_subplan => 'OTHER_GROUPS',
- comment => '',
- cpu_p1 => 20, cpu_p2 => NULL, cpu_p3 => NULL, cpu_p4 => NULL,
- cpu_p5 => NULL, cpu_p6 => NULL, cpu_p7 => NULL, cpu_p8 => NULL,
- parallel_degree_limit_p1 => NULL,
- active_sess_pool_p1 => NULL,
- queueing_p1 => NULL,
- switch_group => '',
- switch_time => NULL,
- switch_estimate => false,
- max_est_exec_time => NULL,
- undo_pool => NULL,
- max_idle_time => NULL,
- max_idle_blocker_time => NULL,
- switch_time_in_call => NULL
- );
- dbms_resource_manager.submit_pending_area();
- END;
复制代码 s62.sql:
- create or replace view LARGE_PROC as
- select * from v$db_object_cache
- where TYPE in ('PACKAGE','PACKAGE BODY','PROCEDURE','TRIGGER','FUNCTION')
- and SHARABLE_MEM > 51200;
- create public synonym LARGE_PROC for
- LARGE_PROC;
复制代码 s63.sql:
- begin
- for rec in ( select index_name from dba_indexes where table_owner='OLTP_USER' and table_name='SALES')
- loop
- execute immediate 'alter index oltp_user.'||rec.index_name||' monitoring usage';
- end loop;
- end;
- /
复制代码 s64.sql:
- create table OLTP_USER.STUDENTS(
- STUD_ID number constraint pk_STUDENTS primary key,
- FNAME varchar2(20),
- LNAME varchar2(20));
- create table OLTP_USER.ATTENDEES(
- STUD_ID number constraint fk_STUD_ID references OLTP_USER.STUDENTS,
- CLASS_ID number constraint fk_CLASS_ID references OLTP_USER.class,
- constraint pk_ATTENDEES primary key (STUD_ID,CLASS_ID))
- organization index;
复制代码 s65.sql:
- begin
- dbms_stats.gather_table_stats('HR','EMPLOYEES',estimate_percent=>100,method_opt=>'for all columns size auto for columns department_id size 254');
- end;
- /
复制代码 s66.sql:
- create tablespace CUST_TBS datafile '/u01/app/oracle/oradata/PROD/Disk1/cust_tbs_01.dbf' size 20971520 segment space management auto;
复制代码 s67.sql:
- create outline outline1 on
- SELECT c.cust_id, SUM(amount_sold)
- FROM
- sh.sales s, sh.customers c
- WHERE s.cust_id = c.cust_id
- GROUP BY c.cust_id;
复制代码 s68.sql:
- create index sh.i_transaction on sh.transaction(USER_ID)
- global partition by hash(USER_ID ) partitions 4;
复制代码 s69.sql:
- begin
- perfstat.statspack.snap(I_SNAP_LEVEL=>7, I_UCOMMENT=>'MANUAL');
- end;
- /
复制代码 s691.sql:
- Rem
- Rem $Header: spauto.sql 16-feb-00.16:49:37 cdialeri Exp $
- Rem
- Rem spauto.sql
- Rem
- Rem Copyright (c) Oracle Corporation 1999, 2000. All Rights Reserved.
- Rem
- Rem NAME
- Rem spauto.sql
- Rem
- Rem DESCRIPTION
- Rem SQL*PLUS command file to automate the collection of STATPACK
- Rem statistics.
- Rem
- Rem NOTES
- Rem Should be run as the STATSPACK owner, PERFSTAT.
- Rem Requires job_queue_processes init.ora parameter to be
- Rem set to a number >0 before automatic statistics gathering
- Rem will run.
- Rem
- Rem MODIFIED (MM/DD/YY)
- Rem cdialeri 02/16/00 - 1191805
- Rem cdialeri 12/06/99 - 1059172, 1103031
- Rem cdialeri 08/13/99 - Created
- Rem
- spool spauto.lis
- --
- -- Schedule a snapshot to be run on this instance every hour, on the hour
- variable jobno number;
- variable instno number;
- begin
- select instance_number into :instno from v$instance;
- dbms_job.submit(:jobno, 'statspack.snap;', trunc(sysdate+5/1440,'MI'), 'trunc(SYSDATE+5/1440,''MI'')', TRUE, :instno);
- commit;
- end;
- /
- prompt
- prompt Job number for automated statistics collection for this instance
- prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- prompt Note that this job number is needed when modifying or removing
- prompt the job:
- print jobno
- prompt
- prompt Job queue process
- prompt ~~~~~~~~~~~~~~~~~
- prompt Below is the current setting of the job_queue_processes init.ora
- prompt parameter - the value for this parameter must be greater
- prompt than 0 to use automatic statistics gathering:
- show parameter job_queue_processes
- prompt
- prompt
- prompt Next scheduled run
- prompt ~~~~~~~~~~~~~~~~~~
- prompt The next scheduled run for this job is:
- select job, next_date, next_sec
- from user_jobs
- where job = :jobno;
- spool off;
- ! sleep 905
- select to_char(SNAP_TIME,'YYYY-MM-DD:HH24:MI:SS') from STATS$SNAPSHOT ;
- begin
- dbms_job.remove(:jobno);
- end;
- /
-
复制代码
|
|