比如说,我有很多update和delete语句,我需要在每一个后面都commit,还是只需要在最后一行写一个commit就行了?这两者有什么区别吗?我自己试了下,好像都一样,但是不知道会不会在什么情况下有区别? 请教大家,谢谢了。。作者: ora_苍狗 时间: 2013-12-2 15:51
如果中间有语句发生错误就不一样了,写了一个测试的例子,看看对你有帮助没有
drop table aatest;
create table aatest
(nid number,nname varchar2(16))
insert into aatest(nid,nname)values(1,'00');
commit;
create or replace procedure aatesta
as
begin
update aatest set nname='step1' where nid=1;
commit;
update aatest set nname='step2' where nid=1;
commit;
update aatest set nname='step3_12345678910101010101' where nid=1;
commit;
exception when others then
rollback;
end;
create or replace procedure aatestb
as
begin
update aatest set nname='step1' where nid=1;
update aatest set nname='step2' where nid=1;
update aatest set nname='step3_12345678910101010101' where nid=1;
commit;
exception when others then
rollback;
end;作者: 〇〇 时间: 2013-12-2 15:56
一个也不写作者: oracle_cj 时间: 2013-12-2 16:00
这个要看情况作者: yi888long 时间: 2013-12-2 16:03
ora_苍狗 发表于 2013-12-2 15:51
如果中间有语句发生错误就不一样了,写了一个测试的例子,看看对你有帮助没有
drop table aatest;
create ...
谢谢回答,不过还是应该看情况吧作者: 260600sz 时间: 2013-12-2 21:39
某种情况如:一个sp中多个dml语句,1.insert into t select ...; commit 2. delete from t where ..;如果语句2失败,则不能保证事务的完整性,表数据t可能会有脏数据作者: 诗意秋雨 时间: 2013-12-2 22:13
一般是在最后放一个吧,特别主要注意数据的一致性的问题