PLSQL - 关联数组错误

PLSQL - Error in associative array

我试图删除一组表,然后我想使用 as select from 重新创建它们。出于好奇,我想用一个关联数组来做到这一点。不幸的是有些事情搞砸了,出现了几个错误,我找不到原因。这是代码:

DECLARE
TYPE t_tbl
IS
  TABLE OF VARCHAR(100) INDEX BY VARCHAR2(100);
  L_Tbl T_Tbl;
  l_key VARCHAR2(100);
BEGIN
  l_tbl('tableA') := 'table1';
  l_tbl('tableB') := 'table2';
  L_Tbl('tableC') := 'table3';
  l_tbl('tableD') := 'table4';

  l_key := l_tbl.first;
  LOOP
    BEGIN
      EXIT WHEN L_Key IS NULL;
      Dbms_Output.Put_Line('Dropping TABLE '|| L_Key ||);
      EXECUTE Immediate 'DROP TABLE ' || L_Key;
      dbms_output.put_line(l_key ||' '|| l_tbl(l_key));
    -- Catch exception if table does not exist
    EXCEPTION
    WHEN OTHERS THEN
      IF SQLCODE != -942 THEN
        Raise;
      END IF;
      EXECUTE IMMEDIATE 'create table schema1.' ||l_key||' as select * from schema2.'||l_tbl(l_key)||;
      l_key := l_tbl.next(l_key);
    END LOOP;
  End;
END;

我收到这些错误:

ORA-06550: line 17, column 56:
PLS-00103: Encountered the symbol ")" when expecting one of the following:

   ( - + case mod new null <an identifier>
   <a double-quoted delimited-identifier> <a bind variable>
   continue avg count current max min prior sql stddev sum
   variance execute forall merge time timestamp interval date
   <a string literal with character set specification>
   <a number> <a single-quoted SQL string> pipe
   <an alternatively-quoted string literal with character set specification>
   <an alternatively-quoted SQL
ORA-06550: line 26, column 102:
PLS-00103: Encountered the symbol ";" when expecting one of the following:

   ( - + case mod new null <an identifier>
   <a double-quoted delimited-identifier> <a bind variable>
   continue avg count current max min prior sql stddev su
ORA-06550: line 29, column 6:
PLS-00103: Encountered the symbol ";" when expecting one of the following:

   loop
The symbol "loop" was substituted for ";" to continue.
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

有人可以给我提示吗?提前致谢!

您有一些未终止的追加操作 ||在线:

Dbms_Output.Put_Line('Dropping TABLE '|| L_Key ||);

EXECUTE IMMEDIATE 'create table schema1.' ||l_key||' as select * from schema2.'||l_tbl(l_key)||;

去掉||在末尾。 您使用 LOOP 的方式也不正确。参考 example:

while elem is not null loop
    dbms_output.put_line(elem || ': ' || var_assoc_varchar(elem));
    elem := var_assoc_varchar.next(elem);   
end loop;

删除 line 17line 25.

行末尾的 ||

并且还在结束块之前结束循环begin....end。在 loop 之前获得 begin 或在 end loop 之前获得 end

           l_key := l_tbl.next(l_key);
      END LOOP;
  END;