Bo's Oracle Station

查看: 2396|回复: 0

课程第37/38次(2017-08-06星期天上下午)

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2017-8-6 11:44:50 | 显示全部楼层 |阅读模式
第三阶段New Feature/OCM Exam Preparation31-38
  1.   select   tp.table_name, tp.partition_name  ,
  2.      tp.high_value , tp.tablespace_name
  3.   from dba_tab_partitions tp
  4. where tp.table_owner='SH' and tp.table_name in ('ORDERS', 'ORDER_ITEMS')
  5. order by   tp.partition_position, tp.table_name;
  6.    
  7.   select  i.index_name , ip.partition_name , decode(ip.status  , null,i.status, ip.status)  
  8.   from dba_indexes i , dba_ind_partitions   ip
  9.   where i.index_name=ip.index_name(+)      and i.table_name='ORDERS'   and i.owner='SH';
复制代码

分区表与DML操作限制:
  1. SQL>
  2. SQL> create table tc ( a  number )
  3.   2  partition by (a)
  4.   3  (partition p1 values less than (a) ,
  5.   4   partition p2 values less than (100) ) ;
  6. partition by (a)
  7.              *
  8. ERROR at line 2:
  9. ORA-14151: invalid table partitioning method


  10. SQL> create table tc ( a  number )
  11.   2   partition  by range (a)
  12.   3  (partition p1 values less than (a) ,
  13.   4   partition p2 values less than (100) )
  14.   5  ;
  15. (partition p1 values less than (a) ,
  16.                                  *
  17. ERROR at line 3:
  18. ORA-14019: partition bound element must be one of: string, datetime or interval literal, number, or MAXVALUE


  19. SQL> create table tc ( a  number )
  20.   2    partition  by range (a)
  21.   3  (partition p1 values less than (10),

  22. SQL>  
  23. SQL>
  24. SQL>  create table tc ( a  number )
  25.   2   partition  by range (a)
  26.   3    (partition p1 values less than (10),
  27.   4   partition p2 values less than (100) );

  28. Table created.

  29. SQL> insert into tc values (100) ;
  30. insert into tc values (100)
  31.             *
  32. ERROR at line 1:
  33. ORA-14400: inserted partition key does not map to any partition


  34. SQL> insert into tc values (99) ;

  35. 1 row created.

  36. SQL> commit;

  37. Commit complete.

  38. SQL> update tc set a=9 where a=99;
  39. update tc set a=9 where a=99
  40.        *
  41. ERROR at line 1:
  42. ORA-14402: updating partition key column would cause a partition change


  43. SQL> update tc set a=98 where a=99;

  44. 1 row updated.

  45. SQL> commit;

  46. Commit complete.

  47. SQL> create table td ( a  number )
  48.   2  partition  by hash (a)
  49.   3  (partition p1  , partition p2 , partition p3 , partition p4 ) ;

  50. Table created.

  51. SQL> insert into td values (1) ;

  52. 1 row created.

  53. SQL> commit;

  54. Commit complete.

  55. SQL> update td values (9) ;
  56. update td values (9)
  57.           *
  58. ERROR at line 1:
  59. ORA-00971: missing SET keyword


  60. SQL> update td set a=9 ;   
  61. update td set a=9
  62.        *
  63. ERROR at line 1:
  64. ORA-14402: updating partition key column would cause a partition change


  65. SQL> update td values (2) ;
  66. update td values (2)
  67.           *
  68. ERROR at line 1:
  69. ORA-00971: missing SET keyword


  70. SQL> update td  set  a=2 ;
  71. update td  set        a=2
  72.        *
  73. ERROR at line 1:
  74. ORA-14402: updating partition key column would cause a partition change


  75. SQL> create table  te (a number )
  76.   2  partition  by system ;

  77. Table created.

  78. SQL> insert into te values (1) ;
  79. insert into te values (1)
  80.             *
  81. ERROR at line 1:
  82. ORA-14701: partition-extended name or bind variable must be used for DMLs on tables partitioned by the System method


  83. SQL>  create table  tf ( a number )
  84.   2  partition by system
  85.   3  partitions 4 ;

  86. Table created.

  87. SQL> insert into tf values (1) ;
  88. insert into tf values (1)
  89.             *
  90. ERROR at line 1:
  91. ORA-14701: partition-extended name or bind variable must be used for DMLs on tables partitioned by the System method


  92. SQL> insert into tf partition sys_p32 values (1) ;
  93. insert into tf partition sys_p32 values (1)
  94.                          *
  95. ERROR at line 1:
  96. ORA-00926: missing VALUES keyword


  97. SQL> insert into tf partition (sys_p32) values (1) ;

  98. 1 row created.

  99. SQL> commit;

  100. Commit complete.

  101. SQL> update tf set a=1999 where a=1;

  102. 1 row updated.

  103. SQL> commit;

  104. Commit complete.

  105. SQL>
复制代码

  1.   select  * from dba_tab_partitions tp
  2.    where tp.table_owner='SH' and tp.table_name='HISTORICAL_NEWSALES';
  3.   
  4.   alter table sh.newsales merge
  5.     partitions sys_p25,  sys_p26
  6.     into partition p_before_3_jan_2005;
  7.   
  8.    ----------------------------
  9.    
  10.      select  * from dba_tab_partitions tp
  11.    where tp.table_owner='SH' and tp.table_name='SHIPMENTS';
  12.    
  13.       select  * from dba_tab_subpartitions tp
  14.    where tp.table_owner='SH' and tp.table_name='SHIPMENTS';
  15.    
  16.    --------
  17.    
  18.    CREATE TABLE sh.sales3
  19.    (    prod_id NUMBER(6) NOT NULL,
  20.        cust_id NUMBER NOT NULL,
  21.         time_id DATE NOT NULL,
  22.         channel_id char(1) NOT NULL,
  23.        promo_id NUMBER (6) NOT NULL,
  24.         quantity_sold NUMBER(3) NOT NULL,
  25.          amount_sold NUMBER(10,2) NOT NULL )
  26. PARTITION BY RANGE (time_id)
  27. SUBPARTITION BY RANGE (cust_id)
  28. SUBPARTITION TEMPLATE
  29.    (  SUBPARTITION sp1 VALUES LESS THAN (50000),
  30.        SUBPARTITION sp2 VALUES LESS THAN (100000),
  31.            SUBPARTITION sp3 VALUES LESS THAN (150000),
  32.                SUBPARTITION sp4 VALUES LESS THAN (MAXVALUE) )
  33. (
  34.   PARTITION   p1  VALUES LESS THAN (TO_DATE('1-4-2007','DD-MM-YYYY')),
  35.   PARTITION   p2  VALUES LESS THAN (TO_DATE('1-7-2007','DD-MM-YYYY')),
  36.   PARTITION   p3  VALUES LESS THAN (TO_DATE('1-8-2007','DD-MM-YYYY')),
  37.   PARTITION    p4 VALUES LESS THAN (TO_DATE('1-1-2008','DD-MM-YYYY'))
  38. );

  39.    ----
  40.         select  * from dba_tab_partitions tp
  41.    where tp.table_owner='SH' and tp.table_name='SALES3';
  42.    
  43.       select  * from dba_tab_subpartitions tp
  44.    where tp.table_owner='SH' and tp.table_name='SALES3';
  45.    
  46.    --------------------
复制代码
删除SQL Access Advisor的模板:

  1.   declare
  2.     name varchar2(30);
  3.     cursor name_cur1 is
  4.       select task_name from user_advisor_templates
  5.         where task_name like 'SQLACCESS%';
  6.   begin
  7.     ---------------------------------------------------------------------------
  8.     --  Get rid of templates, tasks and workloads.  
  9.     ---------------------------------------------------------------------------

  10.     open name_cur1;
  11.   
  12.     loop
  13.       fetch name_cur1 into name;
  14.       exit when name_cur1%NOTFOUND;
  15.   
  16.       dbms_advisor.update_task_attributes(name,null,null,'FALSE','FALSE');
  17.       dbms_advisor.delete_task(name);
  18.     end loop;
  19.   
  20.     close name_cur1;
  21.   
  22.   end;
复制代码
添加SQL Access Advisor的模板:
  1. declare
  2. l_task_id number;
  3. l_name varchar2(30);
  4. begin
  5. l_name := 'SQLACCESS_PARTITION_SMALL';
  6. dbms_advisor.create_task(dbms_advisor.sqlaccess_advisor,l_task_id,l_name,'For demo purposes only');
  7. dbms_advisor.set_task_parameter(l_name,'_PA_MIN_TABLE_SIZE_PART',100);
  8. dbms_advisor.set_task_parameter(l_name,'EXECUTION_TYPE','FULL');
  9. dbms_advisor.set_task_parameter(l_name,'ANALYSIS_SCOPE','ALL');
  10. dbms_advisor.set_task_parameter(l_name,'MODE','COMPREHENSIVE');
  11. dbms_advisor.update_task_attributes(l_name,null,null,'TRUE','TRUE');
  12. end;
  13. /
复制代码





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-23 18:19 , Processed in 0.034626 second(s), 24 queries .

快速回复 返回顶部 返回列表