create or replace procedure pro_testa as begin insert into tabela(id,name) values(1,'OK'); commit; <-----提交 exception when others then rollback; <--------如果出错则回滚. end
上面说的隐式事务太简单了,功能太弱小了: 我的意思是怎么“开始一个事务”,没有一个人能给出一个格式: 比如我要定义多个嵌套事务,怎么开始呢,怎么COMMIT多个嵌套事务呢,一个隐含事务做不到了!就像SQL server的 BEGIN TRAN 类似的东东, ORACLE版就没有高手??????
.... commit; exception when others then rollback; ...
用 create or replace procedure pro_testa as begin insert into tabela(id,name) values(1,'OK'); commit; <-----提交 exception when others then rollback; <--------如果出错则回滚. end 就可以了
如果你想实现嵌套事务,可以用savepoint啊先savepoint name 然后rollback( to savepoint name)
create or replace procedure pro_testa as begin savepoint name insert into tabela(id,name) values(1,'OK'); commit; <-----提交 exception when others then rollback; <--------如果出错则回滚. end
create or replace procedure pro_testa as begin savepoint mystart;---start save point insert into tabela(id,name) values(1,'OK'); commit; <-----提交 exception when others then rollback mystart; <--------如果出错则回滚 to mystart. end
create or replace procedure pro_testa as begin savepoint mystart;---start save point insert into tabela(id,name) values(1,'OK'); commit; <-----提交 exception when others then rollback to mystart; <--------如果出错则回滚 to mystart. end
to drabit: SQL SERVER 不是自动提交事务的;不信回去些个procedure试一下??
to andzen(阿风): sql server 是否自动提交事务跟连接参数有关。 看来你对sql server了解的很少,还需要学习一下事务模式的概念
to drabit: 你不是说SQL server是自动提交的吗,怎么现在又反悔,我只是就事论事,哈哈,至于谁了解的少,自己心里自然明白,不必在这里争这个
to andzen(阿风): 下面是我的原话: 《要知道sqlserver没有办法解决好并发性问题,搞了个自动提交模式(而且是缺省模式),所以才有begin tran命令。》 你居然能理解为“SQL server是自动提交的”,你的理解能力确实有问题。
提供一个PROCEDURE的使用实例,谢谢!1
提供一个PROCEDURE的使用实例,谢谢!
没有人帮忙吗!!!
begin
insert into tabela(id,name) values(1,'OK');
commit; <-----提交
exception
when others then
rollback; <--------如果出错则回滚.
end
我的意思是怎么“开始一个事务”,没有一个人能给出一个格式:
比如我要定义多个嵌套事务,怎么开始呢,怎么COMMIT多个嵌套事务呢,一个隐含事务做不到了!就像SQL server的 BEGIN TRAN 类似的东东,
ORACLE版就没有高手??????
commit;
exception
when others then
rollback;
...
create or replace procedure pro_testa as
begin
insert into tabela(id,name) values(1,'OK');
commit; <-----提交
exception
when others then
rollback; <--------如果出错则回滚.
end
就可以了
然后rollback( to savepoint name)
begin
savepoint name insert into tabela(id,name) values(1,'OK');
commit; <-----提交
exception
when others then
rollback; <--------如果出错则回滚.
end
begin
savepoint mystart;---start save point
insert into tabela(id,name) values(1,'OK');
commit; <-----提交
exception
when others then
rollback mystart; <--------如果出错则回滚 to mystart.
end
begin
savepoint mystart;---start save point
insert into tabela(id,name) values(1,'OK');
commit; <-----提交
exception
when others then
rollback to mystart; <--------如果出错则回滚 to mystart.
end
SQL SERVER 不是自动提交事务的;不信回去些个procedure试一下??
sql server 是否自动提交事务跟连接参数有关。 看来你对sql server了解的很少,还需要学习一下事务模式的概念
你不是说SQL server是自动提交的吗,怎么现在又反悔,我只是就事论事,哈哈,至于谁了解的少,自己心里自然明白,不必在这里争这个