微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

oracle存储过程--循环中使用exception

过程中经常会使用循环来遍历表,取出数据做处理,写回去或者写到其他表中。这个时候,我们会遇到一些问题,当然这里是遇到异常。在循环中如果遇到异常,直接结束循环,回滚事物,是没有错的。有的时候,我们会希望,循环中,只有会产生异常的那些数据才不会回写(写日志什么的),正常数据,还是正常的处理写入,不受异常的数据影响。这个时候就需要加入异常处理。
Error(72,7): 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 
Error(79,3): pls-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:     end not pragma final instantiable order overriding static    member constructor map 
Error(84,33): pls-00103: Encountered the symbol "end-of-file" when expecting one of the following:     end not pragma final instantiable order overriding static    member constructor map

必须承认,我也不知道这个错误提示是什么意思,baidu的内容,瞄了几个,都是格式问题(如:elsif 写成 else if)。好好理了一下代码的逻辑,没弄懂,when other then 下面到底几行算它的内部代码块,dbms这行肯定是,rollback,当然也是,那在后面写个commit,当然也算内部代码块了,那commit就没用了。但是commit写在loop后面,那遇到exception,前面循环的数据也回滚了(还没有提交),这样也打不到效果。在CSDN上看到有人问差不多的问题,看到一个回答,就试了试把exception写在begin 和end的代码块中。 当然,问题就是这么解决的(尴尬的试,我似乎并不想知道为什么会这样,因为没用去找) 这样写,每循环一次提交一下,遇到异常只回滚一次循环的数据。

原文地址:https://www.jb51.cc/oracle/210745.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐