表分区是基于范围或间隔的

时间:2014-07-02 06:55:35

标签: oracle oracle11g

我必须进行数据库分区测试,如果我移动时钟进行测试,我现在创建了表的间隔分区,新的分区没有被创建?它仍在显示旧分区。知道如何解决这个问题吗?如何在oracle数据库中检查表是否为范围分区或区间分区?

使用以下代码删除分区后,我将间隔分区表作为范围分区。

SQL> create or replace procedure partition_delete(var in int) AS 2 v Date := SYSDATE; 3 i number; 4 occurance number; 5 l_drop_sql varchar2(2000); 6 BEGIN 7 execute immediate ' alter table "sch1"."AUDITS" set interval ()'; 8 execute immediate ' alter table "sch1"."ALERTAUDITS" set interval ()'; 9 -- select the tables that starts with either A or L having cfcc as table owner 10 for curs in ( select table_owner,table_name,partition_name,high_value from dba_tab_partitions where table_owner='owner' and REGEXP_LIKE (table_name,'^(A|L)')) LOOP 11 EXECUTE IMMEDIATE 'SELECT ' || curs.high_Value || ' FROM dual' INTO v; -- Conversion of high_value from long to date 12 select round(SYSDATE - v) into i from dual; -- finding the difference between current date and partition creation date 13 select count(*) into occurance from dba_tab_partitions where table_name=curs.table_name; -- Finding the no of existing partitions to the particular table 14 -- occurance>1 indicates table having only one partition is not getting deleted 15 if i > var and occurance > 1 then 16 dbms_output.put_line('The no of days are '||i); 17 dbms_output.put_line('The table name and partition name are '||curs.table_name||'and'||curs.partition_name); 18 l_drop_sql :='alter table "'||curs.table_owner||'"."'||curs.table_name||'" drop partition '||curs.partition_name||' update global indexes'; 19 dbms_output.put_line(l_drop_sql); 20 execute immediate l_drop_sql; 21 end if; 22 end LOOP; 23 execute immediate 'alter table "sch1"."AUDITS" set interval (NUMTOYMINTERVAL(1,''month''))'; 24 execute immediate 'alter table "CFCC"."ALERTAUDITS" set interval (NUMTOYMINTERVAL(1,''month''))'; 25 end; 26 /

创建了程序。

请帮帮我..

2 个答案:

答案 0 :(得分:1)

对于间隔分区,数据字典视图INTERVAL中的列USER_TAB_PARTITIONS设置为YES

SELECT table_name, partition_name, partition_position, INTERVAL, segment_created 
  FROM user_tab_partitions;

  TABLE_NAME  PARTITION_NAME PARTITION_POSITION INTERVAL SEGMENT_CREATED
  MYTABLE     PRE2014        1                  NO       NO
  MYTABLE     SYS_P385       2                  YES      YES
  MYTABLE     SYS_P401       3                  YES      YES
  MYTABLE     SYS_P441       4                  YES      YES

答案 1 :(得分:0)

要查找表是否按时间间隔分区,是否已创建基于该间隔的任何分区,可以检查(DBA)(ALL)(USER)_PART_TABLES.INTERVAL。如果不是NULL,则此列包含在创建表或将表更改为间隔分区时指定的分区间隔。如果为NULL,则表示该表未进行间隔分区。