Oracle错误ORA-00922和ORA-06512

时间:2014-07-31 14:28:24

标签: oracle plsql

我试图运行以下脚本:

SET serveroutput ON
DECLARE

  v_nbr_part        NUMBER := 2;
  v_nbr_subpart     NUMBER := 2;

  v_table_name      VARCHAR2(100) := 'XPTO';
  v_table_shortname     VARCHAR2(100) := 'XPTO';

  v_part_first      NUMBER;
  v_part_last       NUMBER;
  v_subpart_first   NUMBER;
  v_subpart_last    NUMBER;
  v_sql             CLOB := '';
  v_sql_part        CLOB := '';
  v_sql_subpart     CLOB := '';
  v_part_dynam      CLOB := '';
  v_part_keys       CLOB := '';

BEGIN          

  IF v_nbr_part > 0 THEN

      IF v_nbr_subpart > 0 THEN
        v_subpart_first := 0;
        v_subpart_last := v_nbr_subpart-1;    
        v_part_dynam:='';
        FOR i IN v_subpart_first .. v_subpart_last
        LOOP
           v_part_dynam := v_part_dynam || ' SUBPARTITION SP' || i ||' VALUES ('||i||')';
           IF i <> v_subpart_last THEN
              v_part_dynam := v_part_dynam || ',';
           END IF;      
         END LOOP;
         v_sql_subpart:= where_to_save('LDR_SUBTYPE',  v_part_dynam);
         v_part_keys:= ' , "LDR_SUBTYPE" NUMBER NOT NULL ENABLE ';
       END IF;

       v_part_first := 1;
       v_part_last := v_nbr_part;    

       v_sql_part:= to_clob(' PARTITION BY RANGE (PART_KEY) interval(numtodsinterval(1,''day'')) ')|| v_sql_subpart || 
            to_clob(' ( partition EMPTY values less than (to_date(''01-01-2013'',''DD-MM-YYYY'') ) ) ');
       v_part_keys:= ', "PART_KEY" TIMESTAMP (6) NOT NULL ENABLE ' || v_part_keys;
  END IF;

  v_sql:=to_clob(
'CREATE OR REPLACE TABLE "'||v_table_name||'" (
"SEQUENCENUMBER" NUMBER NOT NULL ENABLE,
"LDRID" VARCHAR2(100),
"LDRTYPE" VARCHAR2(50),
"LDR_SUBTYPE" VARCHAR2(50),
"CREATIONTIMESTAMP" TIMESTAMP (6),
"CORRELATIONID" VARCHAR2(4000),
"PARENTLDRID" VARCHAR2(100),
"NUMBEROFCHILDREN" NUMBER,
"PROTOCOLSESSIONID" VARCHAR2(100),
"ACTIVITYID" VARCHAR2(100),
"ACTIVITYINITIALTIMESTAMP" TIMESTAMP (6),
"ACTIVITYELAPSEDTIME" NUMBER,
"CANCELED" CHAR(1),
"REPLACED" CHAR(1),
"INVALIDATIONTIMESTAMP" TIMESTAMP (6),
"INVALIDATEDBYLDRID" VARCHAR2(100),
"INVALIDATESLDRID" VARCHAR2(100),
"OPERATIONID" VARCHAR2(256),
"ACCOUNTID" VARCHAR2(100),
"TOPLEVELID" VARCHAR2(100),
"RESULTCODE" VARCHAR2(100),
"VERSION" NUMBER,
"LDROBJECT" BLOB,
"OBJMETADATA" BLOB,
"OBJKEY" BLOB,
"OBJKEYHASH" VARCHAR2(200) ') ||
v_part_keys ||
to_clob('
)
LOB (OBJKEY) STORE AS SECUREFILE
LOB (LDROBJECT) STORE AS SECUREFILE 
LOB (OBJMETADATA) STORE AS SECUREFILE
') ||
v_sql_part || to_clob(',TABLESPACE OCS LOGGING  NOCOMPRESS  NOCACHE NOPARALLEL');

dbms_output.put_line(dbms_lob.substr(v_sql,4000,1)); //this is line 84!!!!!!!!!
EXECUTE IMMEDIATE v_sql;


EXCEPTION
 WHEN OTHERS THEN
    DBMS_OUTPUT.Put_Line(DBMS_UTILITY.Format_Error_Backtrace);
    DBMS_OUTPUT.Put_Line(SQLERRM);
END;
/

CREATE OR REPLACE FUNCTION where_to_save(LDR_SUBTYPE VARCHAR2, v_part_dynam OUT CLOB)
RETURN CLOB
IS
BEGIN 
  CASE
      WHEN LDR_SUBTYPE = ('IEC') THEN v_part_dynam := v_part_dynam || 'SUBPARTITION SP0 VALUES (IEC)';

      ELSE  v_part_dynam := v_part_dynam || 'SUBPARTITION SP1 VALUES (OTHER)';
  END CASE;

  RETURN v_part_dynam;   

END where_to_save;

脚本对我来说很好,但每次我尝试运行它时都会出现以下错误:

ORA-06512:第84行

ORA-00922:缺少或无效选项

我搜索了很多,我发现修复此问题的唯一方法就是“联系你的DBA”。 我的脚本出了什么问题?我怎样才能解决这个问题? P.S。:我评论过第84行!

2 个答案:

答案 0 :(得分:2)

无法创建或替换表,请先尝试删除它,或者构建一个删除表的pl(如果存在)。

'CREATE TABLE "'||v_table_name||'" (

答案 1 :(得分:-1)

创建或替换表

创建或替换视图 - &gt;是 但不能创建或替换表。此选项不存在。