Oracle中savepoint的使用

create table TABLE5
(
  id   INTEGER,
  name VARCHAR2(10)
);




prompt Importing table table5...
set feedback off
set define off
insert into table5 (ID, NAME)
values (1, '趙1');

insert into table5 (ID, NAME)
values (2, '趙2');

insert into table5 (ID, NAME)
values (3, '趙3');

insert into table5 (ID, NAME)
values (4, '趙4');

insert into table5 (ID, NAME)
values (5, '趙5');

insert into table5 (ID, NAME)
values (6, '趙6');

insert into table5 (ID, NAME)
values (7, '趙7');

insert into table5 (ID, NAME)
values (8, '趙8');

insert into table5 (ID, NAME)
values (9, '趙9');

insert into table5 (ID, NAME)
values (10, '趙10');

prompt Done.

 

 

 

 

savepoint sp1;--完整正確
update table5 SEt name='趙15' where id=5;
select * from table5;--查出來變更了一處
savepoint sp2;--變更了趙15
update table5 SEt name='趙16' where id=6;
savepoint sp3;--變更了趙16
select * from table5;
rollback to sp2;
select * from table5;--查了下,回退到了預期的地方
commit;
-------------------------------
SELECT * FROM table5;
savepoint sp0;
update table5 SEt name='趙5' where id=6;
savepoint sp1;--id還是順序的,趙6變更成了趙5
update table5 set id=100 where name='趙5';
savepoint sp2;--id100的有兩個,趙5有兩個
rollback to sp1;
rollback to sp2;--出錯
rollback to sp0;
rollback to sp1;--出錯
rollback;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章