更新期间 PL/SQL 编译错误
查询
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
FOR
循环使用了错误的语法。错误消息准确地告诉您出了什么问题。而不是单词BEGIN
PUTLOOP
。作为个人规则,我从不使用
BEGIN
IN PL/SQL,只有极少数例外,例如,如果我只需要在某个代码块上捕获异常,并且该代码还不是循环或函数体或其他什么。根据OP的编辑进行编辑:这似乎是其中一种情况。请尝试以下操作:
You're using the wrong syntax for your
FOR
loop. The error message tells you exactly what's wrong. Instead of the wordBEGIN
PUTLOOP
.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: