oracle 中 sqlcode的问题

来源:百度知道 编辑:UC知道 时间:2024/05/14 10:28:44
BEGIN
XXXX

EXCEPTION
WHEN OTHERS
THEN
v_sqlerrm := sqlerrm;
n_sqlcode := sqlcode;
insert into test(sqlerrm,sqlcode) --test为自建表,用与存放错误的
values(v_sqlerrm ,n_sqlcode);
END ;

现在问题是在异常处理中的那个insert 语句出现异常了怎么办?
我的test表实记录 XXX代码中事务执行的情况!
你应该在insert之前回退,把正常事务回退 test 表记录的是哪个异常!

1、你应该在insert之前回退,把正常事务回退;
2、在insert之后提交:
EXCEPTION
WHEN OTHERS
THEN
v_sqlerrm := sqlerrm;
n_sqlcode := sqlcode;
rollback;
insert into test(sqlerrm,sqlcode) --test为自建表,用与存放错误的
values(v_sqlerrm ,n_sqlcode);
commit;
END ;

3、如果insert异常就写不进该表

在exception中写上begin
....
begin
insert into test(sqlerrm,sqlcode) --test为自建表,用与存放错误的
values(v_sqlerrm ,n_sqlcode);
commit;
exception
when others then
rollback;

end;
end;
最后insert错误的时候吧系统时间加上~