更新期间 PL/SQL 编译错误

发布于 2024-12-25 02:37:00 字数 1607 浏览 2 评论 0原文

查询

DECLARE
  v_vendor_id NUMBER;
BEGIN
  FOR vp_rec IN ( SELECT * FROM vpprocess )
    LOOP
      SELECT i.vendor_id INTO v_vendor_id FROM item i, lineitems l WHERE l.itemid = i.itemid AND l.id = vp_rec.lineitemid;
        EXCEPTION
            WHEN no_data_found THEN SELECT 0 INTO v_vendor_id FROM dual;
      UPDATE vpprocess SET vendorid = v_vendor_id WHERE vpprocessid = vp_rec.vpprocessid;
    END;
  END LOOP;
END;

错误信息

 Error starting at line 1 in command:
DECLARE
  v_vendor_id NUMBER;
BEGIN
  FOR vp_rec IN ( SELECT * FROM vpprocess )
    LOOP
      SELECT i.vendor_id INTO v_vendor_id FROM item i, lineitems l WHERE l.itemid = i.itemid AND l.id = vp_rec.lineitemid;
        EXCEPTION
            WHEN no_data_found THEN SELECT 0 INTO v_vendor_id FROM dual;
      UPDATE vpprocess SET vendorid = v_vendor_id WHERE vpprocessid = vp_rec.vpprocessid;
    END;
  END LOOP;
END;
Error report:
ORA-06550: line 7, column 9:
PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:

   begin case declare end exit for goto if loop mod null pragma
   raise return select update while with <an identifier>
   <a double-quoted delimited-identifier> <a bind variable> <<
   close current delete fetch lock insert open rollback
   savepoint set sql execute commit forall merge pipe
ORA-06550: line 11, column 7:
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:

Query

DECLARE
  v_vendor_id NUMBER;
BEGIN
  FOR vp_rec IN ( SELECT * FROM vpprocess )
    LOOP
      SELECT i.vendor_id INTO v_vendor_id FROM item i, lineitems l WHERE l.itemid = i.itemid AND l.id = vp_rec.lineitemid;
        EXCEPTION
            WHEN no_data_found THEN SELECT 0 INTO v_vendor_id FROM dual;
      UPDATE vpprocess SET vendorid = v_vendor_id WHERE vpprocessid = vp_rec.vpprocessid;
    END;
  END LOOP;
END;

Error Message

 Error starting at line 1 in command:
DECLARE
  v_vendor_id NUMBER;
BEGIN
  FOR vp_rec IN ( SELECT * FROM vpprocess )
    LOOP
      SELECT i.vendor_id INTO v_vendor_id FROM item i, lineitems l WHERE l.itemid = i.itemid AND l.id = vp_rec.lineitemid;
        EXCEPTION
            WHEN no_data_found THEN SELECT 0 INTO v_vendor_id FROM dual;
      UPDATE vpprocess SET vendorid = v_vendor_id WHERE vpprocessid = vp_rec.vpprocessid;
    END;
  END LOOP;
END;
Error report:
ORA-06550: line 7, column 9:
PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:

   begin case declare end exit for goto if loop mod null pragma
   raise return select update while with <an identifier>
   <a double-quoted delimited-identifier> <a bind variable> <<
   close current delete fetch lock insert open rollback
   savepoint set sql execute commit forall merge pipe
ORA-06550: line 11, column 7:
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:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心凉怎暖 2025-01-01 02:37:00

您的 FOR 循环使用了错误的语法。错误消息准确地告诉您出了什么问题。而不是单词 BEGIN PUT LOOP

作为个人规则,我从不使用 BEGIN IN PL/SQL,只有极少数例外,例如,如果我只需要在某个代码块上捕获异常,并且该代码还不是循环或函数体或其他什么。

根据OP的编辑进行编辑:这似乎是其中一种情况。请尝试以下操作:

DECLARE
  v_vendor_id NUMBER;
BEGIN
  FOR vp_rec IN ( SELECT * FROM vpprocess )
    LOOP
     BEGIN
       SELECT i.vendor_id INTO v_vendor_id FROM item i, lineitems l WHERE l.itemid = i.itemid AND l.id = vp_rec.lineitemid;
        EXCEPTION
            WHEN no_data_found THEN v_vendor_id := 0;
      END;  
      UPDATE vpprocess SET vendorid = v_vendor_id WHERE vpprocessid = vp_rec.vpprocessid;
    /* END; has been removed */
    END LOOP;
END;

You're using the wrong syntax for your FOR loop. The error message tells you exactly what's wrong. Instead of the word BEGIN PUT LOOP.

As a personal rule, I never use BEGIN IN PL/SQL with very few exceptions, such as if I need to trap exceptions only on a certain block of code, and that code isn't already a loop or function body or whatever.

Edit based on OP's edit: this appears to be one of those cases. Try the following:

DECLARE
  v_vendor_id NUMBER;
BEGIN
  FOR vp_rec IN ( SELECT * FROM vpprocess )
    LOOP
     BEGIN
       SELECT i.vendor_id INTO v_vendor_id FROM item i, lineitems l WHERE l.itemid = i.itemid AND l.id = vp_rec.lineitemid;
        EXCEPTION
            WHEN no_data_found THEN v_vendor_id := 0;
      END;  
      UPDATE vpprocess SET vendorid = v_vendor_id WHERE vpprocessid = vp_rec.vpprocessid;
    /* END; has been removed */
    END LOOP;
END;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文