Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
plsql过程的编译错误_Plsql_Ora 06550 - Fatal编程技术网

plsql过程的编译错误

plsql过程的编译错误,plsql,ora-06550,Plsql,Ora 06550,下面是一个由其他人编写的plsql过程,我要求修复它的编译错误并正确运行它 PROCEDURE DropMyTable IS x number; TYPE cur_typ IS REF CURSOR; --type NAME_TBL is table of VARCHAR2(30); --tab_Table NAME_TBL; tab_Table VARCHAR2S(30); stm

下面是一个由其他人编写的plsql过程,我要求修复它的编译错误并正确运行它

 PROCEDURE DropMyTable IS
  x                number;  
  TYPE cur_typ IS REF CURSOR;
 --type NAME_TBL is table of VARCHAR2(30);
 --tab_Table                 NAME_TBL;
 tab_Table                VARCHAR2S(30);
 stmt                     VARCHAR2(4096);
  stmt2                    VARCHAR2(4096);
    outerCur                 cur_typ;
      rows                     NATURAL := 1000;
    TABLE_DOES_NOT_EXIST     EXCEPTION;
   PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST, -942);
  BEGIN
 stmt2 := 'select distinct G_Tab  from G_SERVE  where G_TYPE=''CAP'''; 
  --Begin
   OPEN outerCur FOR stmt2;
   LOOP
    FETCH outerCur BULK COLLECT INTO
      tab_Table LIMIT rows;
   EXIT WHEN tab_Table.COUNT = 0;

   FOR i IN 1..tab_Table.COUNT LOOP
    --------------------------------------------------------------------
      -- Drop the  tables in G_SERVE.G_TAB
      DBMS_OUTPUT.PUT_LINE('*** Drop  table: ' || tab_Table(i) || ' ***');
      -- BEGIN
      --First drop the optable      
      stmt := 'DROP TABLE ' || tab_Table(i) || '_OPTAB CASCADE CONSTRAINTS';
      DBMS_OUTPUT.PUT_LINE(stmt);
      EXECUTE IMMEDIATE stmt;  
      --drop the base table
      stmt := 'DROP TABLE ' || tab_Table(i) || ' CASCADE CONSTRAINTS';
    DBMS_OUTPUT.PUT_LINE(stmt);
    EXECUTE IMMEDIATE stmt;
      --drop the Package
      stmt := 'DROP PACKAGE  ' || tab_Table(i) || '_PKG';
      DBMS_OUTPUT.PUT_LINE(stmt);
      EXECUTE IMMEDIATE stmt;     
    EXCEPTION
  -- When the table, optab and package  doesn't exist,
  -- ignore error "ORA-00942: table, optab or package does not exist".
   WHEN TABLE_DOES_NOT_EXIST THEN
    DBMS_OUTPUT.PUT_LINE('table, optab or package does not exist');
    DBMS_OUTPUT.PUT_LINE(CHR(9));
   --Re-raises any other errors.
   WHEN OTHERS THEN
   DBMS_OUTPUT.PUT_LINE('Error!');
    RAISE;
     END;
  END LOOP;
 END LOOP;
 --END;
 END DropMyTable;
首先,我注释掉了begging的第4行和第5行代码,并将其更改为现在的样子(从顶部开始的第6行)

另一件事我已经注释掉了2个开始关键字第一次注释掉“开始”可以在后面看到

  stmt2 := 'select distinct gao_table  from GAO_SERVICESIFACE  where GAO_TYPE=''CAPABILITY''';
第二个“BEGIN”关键字在下面的代码行之后被注释掉了

 DBMS_OUTPUT.PUT_LINE('*** Drop  table: ' || tab_Table(i) || ' ***');
因为我怀疑写这段代码的人放了不必要的“BEGIN”关键字(如果我错了,我道歉,因为我不是plsql专家。但是做了所有注释之后,我排除了这么多错误)

但是当我编译上面的代码时,仍然会出现以下两个错误

(一)


您已经注释掉了内部循环中的开始,但没有注释掉其关联的异常和结束。你需要这样开始。此外,当代码仍然需要数组时,不能将数组更改为标量变量(请参考
tab\u Table(i)
等)

代码的适当缩进总是使其更易于遵循:

PROCEDURE DropMyTable IS
  x                number;  
  TYPE cur_typ IS REF CURSOR;
  type NAME_TBL is table of VARCHAR2(30);
  tab_Table                 NAME_TBL;
  --tab_Table                VARCHAR2S(30);
  stmt                     VARCHAR2(4096);
  stmt2                    VARCHAR2(4096);
  outerCur                 cur_typ;
  rows                     NATURAL := 1000;
  TABLE_DOES_NOT_EXIST     EXCEPTION;
  PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST, -942);
BEGIN
  stmt2 := 'select distinct G_Tab  from G_SERVE  where G_TYPE=''CAP'''; 
  --Begin
  OPEN outerCur FOR stmt2;
  LOOP
    FETCH outerCur BULK COLLECT INTO
      tab_Table LIMIT rows;
    EXIT WHEN tab_Table.COUNT = 0;

    FOR i IN 1..tab_Table.COUNT LOOP
      --------------------------------------------------------------------
      -- Drop the  tables in G_SERVE.G_TAB
      DBMS_OUTPUT.PUT_LINE('*** Drop  table: ' || tab_Table(i) || ' ***');
      BEGIN
        --First drop the optable      
        stmt := 'DROP TABLE ' || tab_Table(i) || '_OPTAB CASCADE CONSTRAINTS';
        DBMS_OUTPUT.PUT_LINE(stmt);
        EXECUTE IMMEDIATE stmt;  
        --drop the base table
        stmt := 'DROP TABLE ' || tab_Table(i) || ' CASCADE CONSTRAINTS';
        DBMS_OUTPUT.PUT_LINE(stmt);
        EXECUTE IMMEDIATE stmt;
        --drop the Package
        stmt := 'DROP PACKAGE  ' || tab_Table(i) || '_PKG';
        DBMS_OUTPUT.PUT_LINE(stmt);
        EXECUTE IMMEDIATE stmt;     
      EXCEPTION
        -- When the table, optab and package  doesn't exist,
        -- ignore error "ORA-00942: table, optab or package does not exist".
        WHEN TABLE_DOES_NOT_EXIST THEN
          DBMS_OUTPUT.PUT_LINE('table, optab or package does not exist');
          DBMS_OUTPUT.PUT_LINE(CHR(9));
        --Re-raises any other errors.
        WHEN OTHERS THEN
          DBMS_OUTPUT.PUT_LINE('Error!');
          RAISE;
      END;
    END LOOP;
  END LOOP;
--END;
END DropMyTable;

我已经恢复了BEGIN并恢复了阵列。我不知道是否还有其他错误。

谢谢你的建议,但现在当我编译你修改的代码时,我发现以下错误。错误报告:错误报告:ORA-06550:第2行第3列:PLS-00201:标识符'STMT2'必须声明ORA-06550:第2行第3列:PL/SQL:语句忽略ORA-06550:第4行,第8列:PLS-00201:标识符'OUTERCUR'必须声明ORA-06550:第4行,第3列:PL/SQL:语句忽略ORA-06550:第6行,第11列:PLS-00201:标识符“OUTERCUR”必须声明ORA-06550:第6行,第5列:PL/SQL:SQL语句忽略ORA-06550:第8行,第15列:PLS-00201:标识符“TAB_TABLE.COUNT”必须声明ORA-06550:第8行,第5列:PL/SQL:语句忽略ORA-06550:第10行,第17列:PLS-00201:标识符“TAB_TABLE.COUNT”必须声明为ORA-06550:第10行,第5列:PL/SQL:忽略语句06550。00000-“行%s,列%s:\n%s”*原因:通常是PL/SQL编译错误*措施:我做了2条评论,以便向您展示由于空间有限而产生的所有错误。另外,我认为即使我们是VARCHAR2S类型的变量,它的行为也类似于数组。我不知道您在做什么,但你似乎在第一次开始之前就失去了一切。我只是在我的数据库上编译了这个过程,没有错误。我只是将成功的创建粘贴到我的答案中。
ORA-06550: line 38, column 9:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
   ;
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
PROCEDURE DropMyTable IS
  x                number;  
  TYPE cur_typ IS REF CURSOR;
  type NAME_TBL is table of VARCHAR2(30);
  tab_Table                 NAME_TBL;
  --tab_Table                VARCHAR2S(30);
  stmt                     VARCHAR2(4096);
  stmt2                    VARCHAR2(4096);
  outerCur                 cur_typ;
  rows                     NATURAL := 1000;
  TABLE_DOES_NOT_EXIST     EXCEPTION;
  PRAGMA EXCEPTION_INIT(TABLE_DOES_NOT_EXIST, -942);
BEGIN
  stmt2 := 'select distinct G_Tab  from G_SERVE  where G_TYPE=''CAP'''; 
  --Begin
  OPEN outerCur FOR stmt2;
  LOOP
    FETCH outerCur BULK COLLECT INTO
      tab_Table LIMIT rows;
    EXIT WHEN tab_Table.COUNT = 0;

    FOR i IN 1..tab_Table.COUNT LOOP
      --------------------------------------------------------------------
      -- Drop the  tables in G_SERVE.G_TAB
      DBMS_OUTPUT.PUT_LINE('*** Drop  table: ' || tab_Table(i) || ' ***');
      BEGIN
        --First drop the optable      
        stmt := 'DROP TABLE ' || tab_Table(i) || '_OPTAB CASCADE CONSTRAINTS';
        DBMS_OUTPUT.PUT_LINE(stmt);
        EXECUTE IMMEDIATE stmt;  
        --drop the base table
        stmt := 'DROP TABLE ' || tab_Table(i) || ' CASCADE CONSTRAINTS';
        DBMS_OUTPUT.PUT_LINE(stmt);
        EXECUTE IMMEDIATE stmt;
        --drop the Package
        stmt := 'DROP PACKAGE  ' || tab_Table(i) || '_PKG';
        DBMS_OUTPUT.PUT_LINE(stmt);
        EXECUTE IMMEDIATE stmt;     
      EXCEPTION
        -- When the table, optab and package  doesn't exist,
        -- ignore error "ORA-00942: table, optab or package does not exist".
        WHEN TABLE_DOES_NOT_EXIST THEN
          DBMS_OUTPUT.PUT_LINE('table, optab or package does not exist');
          DBMS_OUTPUT.PUT_LINE(CHR(9));
        --Re-raises any other errors.
        WHEN OTHERS THEN
          DBMS_OUTPUT.PUT_LINE('Error!');
          RAISE;
      END;
    END LOOP;
  END LOOP;
--END;
END DropMyTable;