ORA-14551: cannot perform a DML operation inside a query异常排除

在一个项目中,时不时碰到ORA-14551: cannot perform a DML operation inside a query 错误,定位问题时,发现是在某一个函数的含有for update 的语句抛出异常,这个函数在多个地方调用,调试也没发现异常,后来做了个实验才知道原因,实验如下:
create or replace function f_test return number
is
   l_rec number;
begin
  select 1 into l_rec from dual for update nowait;
  return l_rec;
  Exception
     when others then
         Raise_application_error(-20000, '失败'||sqlerrm);
  return -1;
End;

declare
  l_num number;
begin
  l_num := f_test;                 -------①
  select f_test into l_num from dual;          ----------②
exception
  when others then
    Raise_application_error(-20000, '失败'||sqlerrm);
end;

在①这步没有异常,在②这里就抛出异常了,原来for update 会给记录加锁(暗示你要修改记录),但是在select 同时你又要修改记录,这在oracle是不允许的,所以会抛出ORA-14551异常,其他调用就没有问题。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30741760/viewspace-2098847/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30741760/viewspace-2098847/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值