>oracle和Sqlserver的存储过程里面使用事务是不同的
Sqlserver里面是用的Begin trans ...commit/rollback
oracle里面用的是
savepoint <sptname> ... commit/rollback to savepoint <sptname>;
或者... commit/rollback
oralle一般都使用try catch结构,在catch里面rollback
表 employee和employeeA的字段ID上建立了主键
>例子1:
[效果:]和Sqlserver的
set xact_abort on
>oracle和Sqlserver的存储过程里面使用事务是不同的
Sqlserver里面是用的Begin trans ...commit/rollback
oracle里面用的是
savepoint <sptname> ... commit/rollback to savepoint <sptname>;
或者... commit/rollback
oralle一般都使用try catch结构,在catch里面rollback
表 employee和employeeA的字段ID上建立了主键
>例子1:
[效果:]和Sqlserver的
set xact_abort on
begin tran
...
commit tran
--//语句如下
begin
insert into employee
select 4,'heihei',6,'123412342' from dual;
update employeeA set Age=12 where id=3;
commit;
exception when others then
rollback;
dbms_output.put_line(Sqlerrm);
end;
[注意:] oracle里面的错误信息是通过Sqlerrm变量反映出来,
让语句不往下执行,使用return语句
>例子2:
[效果:]和Sqlserver的
begin tran
...
if @@error >0
begin
rollback tran
return;
end
...
commit tran
如果要对指定dml语句检测的话,就要改成下面的,即对没一个块进行检测
begin
begin
insert into employee
select 4,'heihei',6,'123412342' from dual;
update employeeA set age=9 where id=3;
exception when others then
rollback;
dbms_output.put_line('里层'||Sqlerrm);
return;
end;
begin
insert into employeeA
select 4,'heihei',6,'123412342' from dual;
exception when others then
rollback;
dbms_output.put_line('里层'||Sqlerrm);
return;
end;
commit;
end;