--创建一个分区表
create table scott.testpart
(
TEXTDATE VARCHAR2(8)
)
partition by range ( TEXTDATE )
(
partition p1 values less than ('20090201'),
partition
"p2" values less than ('20090301'),
--注意这里的双引号 partition pm values less than (MAXVALUE)
)
--插入一些数据(顺便实践一下双层循环)DECLARE
i int:=1;
j int:=1;
BEGIN
WHILE i<=3 LOOP
WHILE j<=3 LOOP
insert into scott.testpart values (2009*10000+i*100+j);
j:=j+1;
END LOOP;
i:=i+1;
j:=1;
--注意要重置j,否则就回不到j循环里面了 END LOOP;
END;
--需要先进行分析,否则num_rows列将为空analyze table scott.testpart compute statistics;
--查看各个分区的情况select table_name, partition_name, num_rows from DBA_TAB_PARTITIONS
where table_owner='SCOTT' and table_name='TESTPART';
TABLE_NAME PARTITION_NAME NUM_ROWS
-------------------------- ------------------------------ ----------
TESTPART P1 3
TESTPART PM 3
TESTPART
p2 3
注意p2因为加了引号仍然是小写(但并不显示引号,这点比较讨厌),没加引号的会显示为大写--验证数据确实进入了正确的分区select * from scott.testpart partition(p1);
TEXTDATE
--------
20090101
20090102
20090103
--创建p2时有引号,使用p2时也就需要引号。--特别的,用一些第三方客户端创建分区表时,生成的SQL往往会自动加上引号,而查看DBA_TAB_PARTITIONS时又看不出来,所以遇到下面的问题,可以加个引号试试。select * from scott.testpart partition(p2);
ERROR at line 1:
ORA-02149: Specified partition
does not existselect * from scott.testpart partition(
"p2");
TEXTDATE
--------
20090201
20090202
20090203
--其它相关select * from scott.testpart;
truncate table scott.testpart;
drop table scott.testpart;
posted on 2009-08-18 18:17
Jcat 阅读(257)
评论(0) 编辑 收藏 所属分类:
Database