在varchar字段上创建每月分区

时间:2016-07-18 16:31:10

标签: oracle11g partitioning

专家,我有以下代码在VARCHAR字段上创建每月分区。

  SELECT COUNT(*) INTO FCNT FROM USER_TABLES WHERE TABLE_NAME = 'WORK_RECON_T';

    IF ( FCNT = 1 ) THEN
        DBMS_OUTPUT.PUT_LINE('DROPPING TABLE WORK_RECON_T');
        EXECUTE IMMEDIATE 'DROP TABLE WORK_RECON_T';
        DBMS_OUTPUT.PUT_LINE('DROPPED TABLE WORK_RECON_T');
    END IF;

    EXECUTE IMMEDIATE 'CREATE TABLE WORK_RECON_T (
            ANI VARCHAR (255),
            COMPANYID   VARCHAR (255),
            DIVISION    VARCHAR (255),
            TIMESTAMP   TIMESTAMP,
            OMCPROCESSTIME  VARCHAR (255),
vRange number GENERATED ALWAYS AS
      (to_number(OMCPROCESSTIME)))
partition by range(vRange)
INTERVAL(100)
(partition empty values less than (20160101) )';

OMCPROCESSTIME中的数据如下所示20160718094020。我无法使用此命令创建分区。如果这是正确的方法,请你点亮一下吗?

1 个答案:

答案 0 :(得分:1)

请尝试下面提到的。

declare

v_sql varchar2(2000);

begin

 IF ( FCNT = 1 ) THEN
    DBMS_OUTPUT.PUT_LINE('DROPPING TABLE WORK_RECON_T');
    EXECUTE IMMEDIATE 'DROP TABLE WORK_RECON_T';
    DBMS_OUTPUT.PUT_LINE('DROPPED TABLE WORK_RECON_T');
END IF; 

v_sql:='CREATE TABLE WORK_RECON_T (
            ANI VARCHAR (255),
            COMPANYID   VARCHAR (255),
            DIVISION    VARCHAR (255),
            TIMESTAMP   TIMESTAMP,
            OMCPROCESSTIME  VARCHAR (255),
            vRange number GENERATED ALWAYS AS (to_number(OMCPROCESSTIME)))
partition by range(vRange)
INTERVAL(100)
(partition empty values less than (20160101) )';

execute immediate v_sql;

end;