【问题标题】:Syntax error in for loopfor循环中的语法错误
【发布时间】:2013-04-29 09:23:20
【问题描述】:

从命令的第 1 行开始出错:

DECLARE
   x NUMBER := 0;
   counter NUMBER := 0;
BEGIN
   FOR i IN 1..4 LOOP
      x := x + 1000;
      counter := counter + 1;
      INSERT INTO temp VALUES (x, counter, 'in OUTER loop');
      END;
   END LOOP;
   COMMIT;
END;

错误报告:

ORA-06550: line 11, column 10:
PLS-00103: Encountered the symbol ";" when expecting one of the following:

loop
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

【问题讨论】:

  • 你有ENDEND LOOPEND嵌套corect吗?

标签: for-loop oracle11g ora-06550 pls-00103


【解决方案1】:

对于这种插入模式,您不需要 PL/SQL。以下工作在纯 SQL 中:

create table temp(x number, counter number, text varchar2(20));

insert into temp
select (rownum-1)*1000, rownum-1, 'in OUTER loop'
from dual
connect by level <=4;

【讨论】:

    【解决方案2】:

    第 11 行的第一个 END; 不应该在那里:

    DECLARE
       x NUMBER := 0;
       counter NUMBER := 0;
    BEGIN
       FOR i IN 1..4 LOOP
          x := x + 1000;
          counter := counter + 1;
          INSERT INTO temp VALUES (x, counter, 'in OUTER loop');
       END LOOP;
       COMMIT;
    END;
    

    只有在 INSERT 周围有一个子块时才需要它(例如),例如用于特定异常处理。

    通常在INSERT 中指定列名也会更好:

          INSERT INTO temp(col1, col2, col3) VALUES (x, counter, 'in OUTER loop');
    

    【讨论】:

      猜你喜欢
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多