使用Oracle Database 11g可以创建Interval分区表
2013-09-11 11:13
405 查看
PS:建分区表一定要指定表级默认分区,不指定后续自动建的分区都会搞到user默认表空间上!
也可以修改:alter table DS_CLT_IUB_MR modify default attributes tablespace wcdma_mr;
使用Oracle Database 11g可以创建新类型的Interval分区表,Interval类型分区表,可以根据加载数据,自动创建指定间隔的分区。
比如创建按月分区的分区表:
Create table intervalpart
(c1 number, c2 varchar2(10) , c3 date)
partition by range (c3)
interval(numtoyminterval(1,'MONTH'))
(
partition part1 values less than (to_date('09/15/2007','MM/DD/YYYY')),
partition part2 values less than (to_date('10/15/2007','MM/DD/YYYY')),
partition part3 values less than (to_date('11/15/2007','MM/DD/YYYY'))
)
/
注意如果你的INTERVAL指定错误,则数据库会报出如下错误:
ORA-14752: Interval expression is not a constant of the correct type
下面创建一个以天为间隔的分区表:
SQL> create table sales
2 (
3 sales_id number,
4 sales_dt date
5 ) tablespace wcdma_mr
6 partition by range (sales_dt)
7 INTERVAL (NUMTODSINTERVAL(1,'day'))
8 (
9 partition p090101 values less than (to_date('2009-01-01','yyyy-mm-dd'))
10 );
Table created.
SQL> select table_name,partition_name from user_tab_partitions;
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES P090101
SYS_FBA_HIST_16585 HIGH_PART
插入测试数据:
SQL> begin
2 for i in 1 .. 35 loop
3 insert into sales values(i,trunc(sysdate,'YYYY')+i);
4 end loop;
5 commit;
6 end;
7 /
PL/SQL procedure successfully completed.
观察自动创建的分区:
SQL> select table_name,partition_name from user_tab_partitions;
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES SYS_P47
SALES SYS_P48
SALES SYS_P49
SALES SYS_P50
SALES SYS_P51
SALES SYS_P52
SALES SYS_P53
SALES SYS_P54
SALES SYS_P55
SALES P090101
SALES SYS_P21
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES SYS_P22
SALES SYS_P23
SALES SYS_P24
SALES SYS_P25
SALES SYS_P26
SALES SYS_P27
SALES SYS_P28
SALES SYS_P29
SALES SYS_P30
SALES SYS_P31
SALES SYS_P32
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES SYS_P33
SALES SYS_P34
SALES SYS_P35
SALES SYS_P36
SALES SYS_P37
SALES SYS_P38
SALES SYS_P39
SALES SYS_P40
SALES SYS_P41
SALES SYS_P42
SALES SYS_P43
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES SYS_P44
SALES SYS_P45
SALES SYS_P46
SYS_FBA_HIST_16585 HIGH_PART
37 rows selected.
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SQL> select * from sales partition (sys_p44) ;
SALES_ID SALES_DT
---------- -------------------
24 2009-01-25 00:00:00
SQL> select * from sales partition (sys_p33);
SALES_ID SALES_DT
---------- -------------------
13 2009-01-14 00:00:00
SQL> select * from sales partition (sys_p46);
SALES_ID SALES_DT
---------- -------------------
26 2009-01-27 00:00:00
这一特性极大简化了分区表的维护工作。
也可以修改:alter table DS_CLT_IUB_MR modify default attributes tablespace wcdma_mr;
使用Oracle Database 11g可以创建新类型的Interval分区表,Interval类型分区表,可以根据加载数据,自动创建指定间隔的分区。
比如创建按月分区的分区表:
Create table intervalpart
(c1 number, c2 varchar2(10) , c3 date)
partition by range (c3)
interval(numtoyminterval(1,'MONTH'))
(
partition part1 values less than (to_date('09/15/2007','MM/DD/YYYY')),
partition part2 values less than (to_date('10/15/2007','MM/DD/YYYY')),
partition part3 values less than (to_date('11/15/2007','MM/DD/YYYY'))
)
/
注意如果你的INTERVAL指定错误,则数据库会报出如下错误:
ORA-14752: Interval expression is not a constant of the correct type
下面创建一个以天为间隔的分区表:
SQL> create table sales
2 (
3 sales_id number,
4 sales_dt date
5 ) tablespace wcdma_mr
6 partition by range (sales_dt)
7 INTERVAL (NUMTODSINTERVAL(1,'day'))
8 (
9 partition p090101 values less than (to_date('2009-01-01','yyyy-mm-dd'))
10 );
Table created.
SQL> select table_name,partition_name from user_tab_partitions;
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES P090101
SYS_FBA_HIST_16585 HIGH_PART
插入测试数据:
SQL> begin
2 for i in 1 .. 35 loop
3 insert into sales values(i,trunc(sysdate,'YYYY')+i);
4 end loop;
5 commit;
6 end;
7 /
PL/SQL procedure successfully completed.
观察自动创建的分区:
SQL> select table_name,partition_name from user_tab_partitions;
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES SYS_P47
SALES SYS_P48
SALES SYS_P49
SALES SYS_P50
SALES SYS_P51
SALES SYS_P52
SALES SYS_P53
SALES SYS_P54
SALES SYS_P55
SALES P090101
SALES SYS_P21
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES SYS_P22
SALES SYS_P23
SALES SYS_P24
SALES SYS_P25
SALES SYS_P26
SALES SYS_P27
SALES SYS_P28
SALES SYS_P29
SALES SYS_P30
SALES SYS_P31
SALES SYS_P32
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES SYS_P33
SALES SYS_P34
SALES SYS_P35
SALES SYS_P36
SALES SYS_P37
SALES SYS_P38
SALES SYS_P39
SALES SYS_P40
SALES SYS_P41
SALES SYS_P42
SALES SYS_P43
TABLE_NAME PARTITION_NAME
------------------------------ ------------------------------
SALES SYS_P44
SALES SYS_P45
SALES SYS_P46
SYS_FBA_HIST_16585 HIGH_PART
37 rows selected.
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SQL> select * from sales partition (sys_p44) ;
SALES_ID SALES_DT
---------- -------------------
24 2009-01-25 00:00:00
SQL> select * from sales partition (sys_p33);
SALES_ID SALES_DT
---------- -------------------
13 2009-01-14 00:00:00
SQL> select * from sales partition (sys_p46);
SALES_ID SALES_DT
---------- -------------------
26 2009-01-27 00:00:00
这一特性极大简化了分区表的维护工作。
相关文章推荐
- 使用Oracle Database 11g创建Interval分区表
- 使用Oracle Database 11g创建Interval分区表
- 《Oracle Database 11g SQL 开发指南》学习笔记——第三章_使用SQL*PLUS
- 在C++Builder里创建可以被Visual C++使用的DLL
- Oracle技术之11g分区表按时间自动创建
- 使用jquery animate创建平滑滚动效果(可以是到顶部、到底部或指定地方)
- 如何创建一个静态库文件,并打包在模拟器和真机上都可以使用。
- Oracle 11g Data Guard 使用duplicate from active database 创建 standby database
- NumPy中的乘法运算符 * 指示按元素计算,矩阵乘法可以使用 dot 函数或创建矩阵对象实现
- Oracle 11g Data Guard 使用duplicate from active database 创建 standby database .
- 在C++Builder里创建可以被Visual C++使用的DLL
- 使用Openssl 创建可以被Torando使用的crt证书以及Key密钥
- 11g DG使用duplicate from active database 创建 物理 standby database
- Oracle 11G 使用duplicate from active database 创建DG
- Oracle Database 11g Express Edition 使用小结(windows)
- Oracle 11g 环境,使用utl_smtp创建一个存储过程来发送邮件
- 使用Oracle SQLDeveloper(Oracle 11g)连接数据库并创建用户
- 使用类的静态字段和构造函数,我们可以跟踪某个类所创建对象的个数。请写一个类,在任何时候都可以向它查询“你已经创建了多少个对象?”。
- Oracle 自动拓展分区的实现(11g后使用interval分区)
- shell脚本操作mysql数据库,使用mysql的-e参数可以执行各种sql的(创建,删除,增,删,改、查)等各种操作