在Oracle函数中进行insert操做就会报 ORA-14551: cannot perform a DML operation inside a query 数据库
问题缘由:
对数据库有写操做(insert、update、delete、create、alter、commit)的函数,没法简单的用SQL来调用的
ide
解决方法:函数
须要再声明添加PRAGMA AUTONOMOUS_TRANSACTION;orm
例如:事务
create or replace function update_contractDate(v_contractId in contract.id%type, v_contractBeginDateStr in varchar2)
return number
as
pragma autonomous_transaction;
it
PRAGMA AUTONOMOUS_TRANSACTION声明为自治事务io
当前的函数做为已有事务的子事务运行,子事务的commit,rollback操做不影响父事务的状态
在一个事务中能够定义一个或几个自治事务,自治事务能够独立commit,不会对外层事务产生影响,一样外层事务的rollback也对自治事务没有影响,一般能够考虑将自治事务定义成一个过程,在外层的事务中调用。function