[英]How do I handle the exception in this pl/sql for loop correctly?
First off, I'm a relative newbie to PL/SQL so I might be missing something trivial. 首先,我是PL / SQL的新手,所以我可能会错过一些琐碎的事情。
Here is a snippet of code that I'm having issues with running - 这是我在运行时遇到问题的一小段代码-
FOR indx IN 1 .. arr.COUNT
LOOP
SELECT COUNT(*), ca.cities
INTO tmp_count, affected_cities
FROM PDB.utilities ca
WHERE (ca.app_city_id = cityid
AND ca.app_plumbing_id = arr(indx))
AND( BITAND(options1,2) = 2
OR BITAND(options1,1) = 1)
GROUP BY ca.cities;
IF tmp_count >=0 THEN
-- We have an affected app so collect metrics
IF plumbings(indx_mv) ='0Ci30000000GsBN' THEN
count_wrigley:= count_wrigley+tmp_count;
END IF;
counter:= counter+tmp_count; --overall count.
tmp_count:=0;
affected_cities:=null;
END IF;
EXCEPTION -- error thrown here !
WHEN NO_DATA_FOUND THEN
CONTINUE;
END;
END LOOP; -- Error thrown here too.
And here is my error trace - 这是我的错误跟踪-
Error report:
ORA-06550: line 64, column 13:
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> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
ORA-06550: line 68, column 11:
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:
It's worth noting that the block fails only with the exception handling and compiles successfully otherwise. 值得注意的是,该块仅在异常处理后失败,否则将成功编译。 So my guess is I'm doing something wrong there? 所以我猜我在那儿做错了吗?
Any help would be greatly appreciated! 任何帮助将不胜感激! Thanks 谢谢
EXCEPTION aligns with BEGIN ... END blocks. EXCEPTION与BEGIN ... END块对齐。 There is no BEGIN inside your loop, so there should be no exception either. 循环中没有BEGIN,因此也不应该例外。
It seems the purpose of the exception is to suppress NO_DATA_FOUND errors inside the loop. 看起来异常的目的是抑制循环内的NO_DATA_FOUND错误。 So to fix this error you need to put a BEGIN / END block in the loop too. 因此,要解决此错误,您还需要在循环中放置一个BEGIN / END块。 (Ah, you have an END just no BEGIN - your code would hurl with the EXCEPTION block). (嗯,您只有一个END而没有BEGIN-您的代码会在EXCEPTION块中抛出)。
FOR indx IN 1 .. arr.COUNT
LOOP
BEGIN
SELECT COUNT(*), ca.cities
INTO tmp_count, affected_cities
FROM PDB.utilities ca
....
EXCEPTION
WHEN NO_DATA_FOUND THEN
CONTINUE;
END;
END LOOP;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.