oralce study notes (b)

Partition Cleanup:

--范围分区示例
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')),
      the SELECT rownum,
           Within last values less P8 Partition (the TO_DATE ( '2012-09-01', 'YYYY-the MM-DD')), 
           Partition P9 less Within last values (the TO_DATE ( '2012-10-01', 'YYYY-the MM-DD') ), 
           Partition P10 less Within last values (the TO_DATE ( '2012-11-01', 'YYYY-the MM-DD')), 
           Partition P11 less Within last values (the TO_DATE ( '2012-12-01', 'the MM-DD-YYYY ')), 
           Partition P12 less Within last values (the TO_DATE (' 2013-01-01 ',' YYYY-the MM-DD ')), 
           Partition P_max values less Within last (MAXVALUE) 
           ) 
           ; 

- the following is inserted randomly throughout the year date number and the number representing the meaning Fujian (591-599) records a random number, a total of 100,000, as follows: 
INSERT INTO range_part_tab (ID, deal_date, area_code, Contents) 
             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; 
the commit; 

- Analysis of the partition table Common principles inserted 
drop Table norm_tab purge; 
Create Table norm_tab (Number ID, DATE deal_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;
the commit; 


- easily removed example partitioning
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');

  

Guess you like

Origin www.cnblogs.com/sunliyuan/p/11545129.html