--範圍分割槽示例
drop table range_part_tab purge;
--注意,此分割槽為範圍分割槽
create table range_part_tab (id number,deal_date date,area_code number,contents varchar2(4000))
partition by range (deal_date)
(partition p1 values less than (to_date('2012-02-01', 'yyyy-mm-dd')),
partition p2 values less than (to_date('2012-03-01', 'yyyy-mm-dd')),
partition p3 values less than (to_date('2012-04-01', 'yyyy-mm-dd')),
partition p4 values less than (to_date('2012-05-01', 'yyyy-mm-dd')),
partition p5 values less than (to_date('2012-06-01', 'yyyy-mm-dd')),
partition p6 values less than (to_date('2012-07-01', 'yyyy-mm-dd')),
partition p7 values less than (to_date('2012-08-01', 'yyyy-mm-dd')),
partition p8 values less than (to_date('2012-09-01', 'yyyy-mm-dd')),
partition p9 values less than (to_date('2012-10-01', 'yyyy-mm-dd')),
partition p10 values less than (to_date('2012-11-01', 'yyyy-mm-dd')),
partition p11 values less than (to_date('2012-12-01', 'yyyy-mm-dd')),
partition p12 values less than (to_date('2013-01-01', 'yyyy-mm-dd')),
partition p_max values less than (maxvalue)
);
插入資料:
--以下是插入2023年一整年日期隨機數和表示福建地區號含義(591到599)的隨機數記錄,共有10萬條,如下:
insert into range_part_tab (id,deal_date,area_code,contents)
select rownum,
to_date( to_char(sysdate-365,'j')+trunc(dbms_random.value(0,365)),'j'),
ceil(dbms_random.value(590,599)),
rpad('*',400,'*')
from dual
connect by rownum <= 100000;
commit;
--分割槽原理分析之普通表插入
drop table norm_tab purge;
create table norm_tab (id number,deal_date date,area_code number,contents varchar2(4000));
insert into norm_tab(id,deal_date,area_code,contents)
select rownum,
to_date( to_char(sysdate-365,'j')+trunc(dbms_random.value(0,365)),'j'),
ceil(dbms_random.value(590,599)),
rpad('*',400,'*')
from dual
connect by rownum <= 100000;
commit;
--分割槽清除的方便例子
delete from norm_tab where deal_date>=to_date('2012-09-01', 'yyyy-mm-dd') and deal_date <= to_date('2012-09-30', 'yyyy-mm-dd');
--為了後續章節試驗的方便,本處暫且將刪除的記錄回退。
rollback;
select * from range_part_tab partition(p9);
alter table range_part_tab truncate partition p9;
set linesize 1000
set autotrace on
select count(*) from normal_tab where deal_date>=to_date('2012-09-01', 'yyyy-mm-dd') and deal_date <= to_date('2012-09-30', 'yyyy-mm-dd');
select count(*) from range_part_tab where deal_date>=to_date('2012-09-01', 'yyyy-mm-dd') and deal_date <= to_date('2012-09-30', 'yyyy-mm-dd');
drop table mid_table purge;
create table mid_table (id number ,deal_date date,area_code number,contents varchar2(4000));
select count(*) from range_part_tab partition(p8);
---當然,除了上述用partition(p8)的指定分割槽名查詢外,也可以採用分割槽條件代入查詢:
select count(*) from range_part_tab where deal_date>=to_date('2012-08-01', 'yyyy-mm-dd') and deal_date <= to_date('2012-08-31', 'yyyy-mm-dd');
--以下命令就是經典的分割槽交換:
alter table range_part_tab exchange partition p8 with table mid_table;
--查詢發現分割槽8資料不見了。
select count(*) from range_part_tab partition(p8);
---而普通表記錄由剛才的0條變為8628條了,果然實現了交換。
select count(*) from mid_table ;
ORACLE建立分割槽表及分割槽表的資料遷移
對於目前資料量較大的表,report ap stat hour 2個月有1900萬 client offline history 2個月有4800萬 如果儲存超過一年資料將達數億,對這種級別的資料索引優化已經達不到要求的 15秒之內完成查詢 因此需要進行按月分表,使用oracle11g的新特性int...
建立mysql分割槽表及操作
建立分割槽表按月份分割槽 create table o order id int auto increment comment 序號 orderid varchar 200 comment 訂單號 account varchar 50 comment 帳號 status int comment 狀態...
hive 分割槽表 Hive的DDL分割槽表建立
1.單分割槽表 建立表t user,指定分割槽hive xiaoliu create table t user id int,name string partitioned by country string row format delimited fields terminated by xia...