Feb 17, 2016

SAVEPOINT


SAVEPOINT identify a point in a transaction to which you can later roll back.

Example

create table countries (region_id number,region_name varchar2(100),country_id varchar2(100)) ;
insert into COUNTRIES (REGION_ID, REGION_NAME, COUNTRY_ID) values (33, 'Middle East', null);
insert into COUNTRIES (REGION_ID, REGION_NAME, COUNTRY_ID) values (5, null, 'NG');

UPDATE countries SET region_name = 'Middle East' WHERE region_name = 'Middle East and Africa';

SAVEPOINT reg_rename;

UPDATE countries SET country_id = 'ZM'  WHERE region_id = 5;

SAVEPOINT zambia;

UPDATE countries SET country_id = 'NG'  WHERE region_id = 5 ;

SAVEPOINT nigeria;

UPDATE countries SET country_id = 'ZW'  WHERE region_id = 5;

SAVEPOINT zimbabwe;

UPDATE countries SET country_id = 'EG' WHERE  region_id = 5;

SAVEPOINT egypt;

ROLLBACK TO SAVEPOINT nigeria;

COMMIT;

No comments: