【问题标题】:PLSQL - Error in associative arrayPLSQL - 关联数组中的错误
【发布时间】:2015-06-15 14:54:23
【问题描述】:

我试图删除一组表,然后我想使用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:

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

【问题讨论】:

  • 先删除表然后尝试重新创建似乎是倒退。你的意思是创建 b 作为 select * from a;删除表a; ???
  • 1.删除表表A; 2. CREATE TABLE tableA AS SELECT * FROM table1;
  • 请贴出运行时遇到的错误
  • 用我得到的错误更新了我的帖子

标签: oracle plsql associative-array


【解决方案1】:

你有一些未终止的追加操作 ||上线:

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;

【讨论】:

    【解决方案2】:

    删除line 17line 25中行尾的||

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-27
      • 2017-05-10
      • 1970-01-01
      • 2018-02-12
      • 2015-08-16
      • 2017-07-18
      • 2016-10-12
      相关资源
      最近更新 更多