|
第三阶段New Feature/OCM Exam Preparation(31-38)- select tp.table_name, tp.partition_name ,
- tp.high_value , tp.tablespace_name
- from dba_tab_partitions tp
- where tp.table_owner='SH' and tp.table_name in ('ORDERS', 'ORDER_ITEMS')
- order by tp.partition_position, tp.table_name;
-
- select i.index_name , ip.partition_name , decode(ip.status , null,i.status, ip.status)
- from dba_indexes i , dba_ind_partitions ip
- where i.index_name=ip.index_name(+) and i.table_name='ORDERS' and i.owner='SH';
复制代码
分区表与DML操作限制:
- SQL>
- SQL> create table tc ( a number )
- 2 partition by (a)
- 3 (partition p1 values less than (a) ,
- 4 partition p2 values less than (100) ) ;
- partition by (a)
- *
- ERROR at line 2:
- ORA-14151: invalid table partitioning method
- SQL> create table tc ( a number )
- 2 partition by range (a)
- 3 (partition p1 values less than (a) ,
- 4 partition p2 values less than (100) )
- 5 ;
- (partition p1 values less than (a) ,
- *
- ERROR at line 3:
- ORA-14019: partition bound element must be one of: string, datetime or interval literal, number, or MAXVALUE
- SQL> create table tc ( a number )
- 2 partition by range (a)
- 3 (partition p1 values less than (10),
- SQL>
- SQL>
- SQL> create table tc ( a number )
- 2 partition by range (a)
- 3 (partition p1 values less than (10),
- 4 partition p2 values less than (100) );
- Table created.
- SQL> insert into tc values (100) ;
- insert into tc values (100)
- *
- ERROR at line 1:
- ORA-14400: inserted partition key does not map to any partition
- SQL> insert into tc values (99) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> update tc set a=9 where a=99;
- update tc set a=9 where a=99
- *
- ERROR at line 1:
- ORA-14402: updating partition key column would cause a partition change
- SQL> update tc set a=98 where a=99;
- 1 row updated.
- SQL> commit;
- Commit complete.
- SQL> create table td ( a number )
- 2 partition by hash (a)
- 3 (partition p1 , partition p2 , partition p3 , partition p4 ) ;
- Table created.
- SQL> insert into td values (1) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> update td values (9) ;
- update td values (9)
- *
- ERROR at line 1:
- ORA-00971: missing SET keyword
- SQL> update td set a=9 ;
- update td set a=9
- *
- ERROR at line 1:
- ORA-14402: updating partition key column would cause a partition change
- SQL> update td values (2) ;
- update td values (2)
- *
- ERROR at line 1:
- ORA-00971: missing SET keyword
- SQL> update td set a=2 ;
- update td set a=2
- *
- ERROR at line 1:
- ORA-14402: updating partition key column would cause a partition change
- SQL> create table te (a number )
- 2 partition by system ;
- Table created.
- SQL> insert into te values (1) ;
- insert into te values (1)
- *
- ERROR at line 1:
- ORA-14701: partition-extended name or bind variable must be used for DMLs on tables partitioned by the System method
- SQL> create table tf ( a number )
- 2 partition by system
- 3 partitions 4 ;
- Table created.
- SQL> insert into tf values (1) ;
- insert into tf values (1)
- *
- ERROR at line 1:
- ORA-14701: partition-extended name or bind variable must be used for DMLs on tables partitioned by the System method
- SQL> insert into tf partition sys_p32 values (1) ;
- insert into tf partition sys_p32 values (1)
- *
- ERROR at line 1:
- ORA-00926: missing VALUES keyword
- SQL> insert into tf partition (sys_p32) values (1) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> update tf set a=1999 where a=1;
- 1 row updated.
- SQL> commit;
- Commit complete.
- SQL>
复制代码
- select * from dba_tab_partitions tp
- where tp.table_owner='SH' and tp.table_name='HISTORICAL_NEWSALES';
-
- alter table sh.newsales merge
- partitions sys_p25, sys_p26
- into partition p_before_3_jan_2005;
-
- ----------------------------
-
- select * from dba_tab_partitions tp
- where tp.table_owner='SH' and tp.table_name='SHIPMENTS';
-
- select * from dba_tab_subpartitions tp
- where tp.table_owner='SH' and tp.table_name='SHIPMENTS';
-
- --------
-
- CREATE TABLE sh.sales3
- ( prod_id NUMBER(6) NOT NULL,
- cust_id NUMBER NOT NULL,
- time_id DATE NOT NULL,
- channel_id char(1) NOT NULL,
- promo_id NUMBER (6) NOT NULL,
- quantity_sold NUMBER(3) NOT NULL,
- amount_sold NUMBER(10,2) NOT NULL )
- PARTITION BY RANGE (time_id)
- SUBPARTITION BY RANGE (cust_id)
- SUBPARTITION TEMPLATE
- ( SUBPARTITION sp1 VALUES LESS THAN (50000),
- SUBPARTITION sp2 VALUES LESS THAN (100000),
- SUBPARTITION sp3 VALUES LESS THAN (150000),
- SUBPARTITION sp4 VALUES LESS THAN (MAXVALUE) )
- (
- PARTITION p1 VALUES LESS THAN (TO_DATE('1-4-2007','DD-MM-YYYY')),
- PARTITION p2 VALUES LESS THAN (TO_DATE('1-7-2007','DD-MM-YYYY')),
- PARTITION p3 VALUES LESS THAN (TO_DATE('1-8-2007','DD-MM-YYYY')),
- PARTITION p4 VALUES LESS THAN (TO_DATE('1-1-2008','DD-MM-YYYY'))
- );
- ----
- select * from dba_tab_partitions tp
- where tp.table_owner='SH' and tp.table_name='SALES3';
-
- select * from dba_tab_subpartitions tp
- where tp.table_owner='SH' and tp.table_name='SALES3';
-
- --------------------
复制代码 删除SQL Access Advisor的模板:
- declare
- name varchar2(30);
- cursor name_cur1 is
- select task_name from user_advisor_templates
- where task_name like 'SQLACCESS%';
- begin
- ---------------------------------------------------------------------------
- -- Get rid of templates, tasks and workloads.
- ---------------------------------------------------------------------------
- open name_cur1;
-
- loop
- fetch name_cur1 into name;
- exit when name_cur1%NOTFOUND;
-
- dbms_advisor.update_task_attributes(name,null,null,'FALSE','FALSE');
- dbms_advisor.delete_task(name);
- end loop;
-
- close name_cur1;
-
- end;
复制代码 添加SQL Access Advisor的模板:- declare
- l_task_id number;
- l_name varchar2(30);
- begin
- l_name := 'SQLACCESS_PARTITION_SMALL';
- dbms_advisor.create_task(dbms_advisor.sqlaccess_advisor,l_task_id,l_name,'For demo purposes only');
- dbms_advisor.set_task_parameter(l_name,'_PA_MIN_TABLE_SIZE_PART',100);
- dbms_advisor.set_task_parameter(l_name,'EXECUTION_TYPE','FULL');
- dbms_advisor.set_task_parameter(l_name,'ANALYSIS_SCOPE','ALL');
- dbms_advisor.set_task_parameter(l_name,'MODE','COMPREHENSIVE');
- dbms_advisor.update_task_attributes(l_name,null,null,'TRUE','TRUE');
- end;
- /
复制代码
|
|