ITPub博客

首页 > 数据库 > Oracle > Oracle OCP 1Z0 053 Q17(Auto Partition 自动分区)

Oracle OCP 1Z0 053 Q17(Auto Partition 自动分区)

原创 Oracle 作者:abstractcyj 时间:2016-04-05 09:28:13 0 删除 编辑
17.The INV_HISTORY table is created using the command: 
SQL>CREATE TABLE INV_HISTORY (inv_no NUMBER(3), inv_date DATE, inv_amt NUMBER(10,2)) 
partition by range (inv_date) interval 
(numtoyminterval(1,'month')) (partition p0 
values less than (to_date('01-01-2005','dd-mm-yyyy')), partition p1 values less than 
(to_date('01-01-2006','dd-mm-yyyy'))); 
The following data has been inserted into the INV_HISTORY table : 
INV_NO INV_DATE INV_AMT
1 30-dec-2004 1000
2 30-dec-2005 2000
3 1-feb-2006 3000
4 1-mar-2006 4000
5 1-apr-2006 5000 


You would like to store the data belonging to the year 2006 in a single partition and issue the command: 
SQL> ALTER TABLE inv_history MERGE PARTITIONS 
FOR(TO_DATE('15-feb-2006','dd-mon-yyyy')), FOR(TO_DATE('15-apr-2006')) INTO PARTITION sys_py; 
What would be the outcome of this command? 
A. It executes successfully, and the transition point is set to '1-apr-2006'. 
B. It executes successfully, and the transition point is set to '15-apr-2006'. 
C. It produces an error because the partitions specified for merging are not adjacent. 
D. It produces an error because the date values specified in the merge do not match the date values 
stored in the table. 
Answer: C 

这里, 11g之后使用interval来实现自动扩展分区,简化了维护。
 interval (numtoyminterval(1,'month'))一个月一个分区.

插入数据之后,产生了新的分区:



实验:
SQL> CREATE TABLE INV_HISTORY (inv_no NUMBER(3), inv_date DATE, inv_amt NUMBER(10,2)) 
  2  partition by range (inv_date) interval 
  3  (numtoyminterval(1,'month')) 
  4  (partition p0 values less than (to_date('01-01-2005','dd-mm-yyyy')), 
  5  partition p1 values less than  (to_date('01-01-2006','dd-mm-yyyy')));


Table created.


SQL> insert into INV_HISTORY values(1, to_date('30-dec-2004', 'dd-mon-yyyy'), 1000);


1 row created.


SQL> insert into INV_HISTORY values(2, to_date('30-dec-2005', 'dd-mon-yyyy'), 1000);


1 row created.


SQL> insert into INV_HISTORY values(3, to_date('1-feb-2006', 'dd-mon-yyyy'), 1000);


1 row created.


SQL> insert into INV_HISTORY values(4, to_date('30-mar-2006', 'dd-mon-yyyy'), 1000);


1 row created.


SQL> insert into INV_HISTORY values(5, to_date('30-apr-2006', 'dd-mon-yyyy'), 1000);


1 row created.


SQL> commit;


Commit complete.


SQL> ALTER TABLE inv_history MERGE PARTITIONS
  2  FOR(TO_DATE('15-feb-2006','dd-mon-yyyy')), FOR(TO_DATE('15-apr-2006')) INTO PARTITION sys_py;
ALTER TABLE inv_history MERGE PARTITIONS
*
ERROR at line 1:
ORA-14274: partitions being merged are not adjacent

这里说的是分区不相邻,不能合并

改变合并分区的条件:

SQL> ALTER TABLE inv_history MERGE PARTITIONS
  2      FOR(TO_DATE('15-feb-2006','dd-mon-yyyy')), FOR(TO_DATE('15-mar-2006')) INTO PARTITION sys_py;
ALTER TABLE inv_history MERGE PARTITIONS
Table altered.

合并分区之后,分区调整为:


从这里看到,Oracle 11G的自动分区特性还算是挺只能的

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8520577/viewspace-2075295/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
曾从事java方向开发多年。近年已经转入数据库方向。主要擅长SQL优化,Oracle数据库问题诊断,Oracle备份与恢复等。服务于医药物流,医院等行业

注册时间:2010-01-26

  • 博文量
    602
  • 访问量
    1091616