在存储过程A中有这样的语句:
procedureA
begin
.....
insert .... select functionB(COL1,..) from t1;
....
commit;
exception
when others then
rollback;(将所有insert的数据回滚掉)
end procedureA;
而functionB有时会因为参数问题而无法正常计算,为了记录这些异常,在functionB中写了这样的语句:exception
when others then
insert into t2...
commit;但functionB中的commit语句会将procedureA的未提交的数据也提交,造成数据不一致。
怎么办好呢?还望高手指点,不甚感激!
procedureA
begin
.....
insert .... select functionB(COL1,..) from t1;
....
commit;
exception
when others then
rollback;(将所有insert的数据回滚掉)
end procedureA;
而functionB有时会因为参数问题而无法正常计算,为了记录这些异常,在functionB中写了这样的语句:exception
when others then
insert into t2...
commit;但functionB中的commit语句会将procedureA的未提交的数据也提交,造成数据不一致。
怎么办好呢?还望高手指点,不甚感激!
删除procedureA中原来的commit
在procedureA的end前加一个commit就OKay了。
(1) procedureA插入数据,没有发生异常"在procedureA的end前加一个commit",它能COMMIT functionB 产生异常所插入的数据和procedureA所插入的数据(2) procedureA插入数据,发生异常
when others then
rollback;(将所有insert的数据回滚掉)
它应该能ROLLBACK掉functionB 产生异常所插入的数据和procedureA所插入的数据我是这样理解的,没有测试过,你自己弄两个表测试下。
對於異常記錄部分,可以使用自治事务。
CREATE OR REPLACE function err_log(....) as
PRAGMA AUTONOMOUS_TRANSACTION; -- 創建自治事務,保存程序異常.
begin
;
commit; -- 只作用於此函數,不對外層擴展。
end;