Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Reusing a SAVEPOINT With ROLLBACK

DROP TABLE emp_name CASCADE CONSTRAINTS PURGE;

DROP INDEX empname_ix;


CREATE TABLE emp_name
AS
SELECT employee_id,
last_name,
salary
FROM employees;

CREATE UNIQUE INDEX empname_ix ON emp_name (
employee_id);


DECLARE
emp_id employees.employee_id%TYPE;
emp_lastname employees.last_name%TYPE;
emp_salary employees.salary%TYPE;
BEGIN
SELECT employee_id,
last_name,
salary
INTO emp_id,emp_lastname,emp_salary
FROM employees
WHERE employee_id = 120;

SAVEPOINT my_savepoint;

UPDATE emp_name
SET salary = salary * 1.1
WHERE employee_id = emp_id;

DELETE FROM emp_name
WHERE employee_id = 130;

SAVEPOINT my_savepoint; -- move my_savepoint to current poin

INSERT INTO emp_name
VALUES (emp_id,
emp_lastname,
emp_salary);
EXCEPTION
WHEN dup_val_on_index THEN
ROLLBACK TO my_savepoint;

dbms_output.Put_line('Transaction rolled back.');
END;
/




OUTPUT :-

Transaction rolled back.

PL/SQL procedure successfully completed.

Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-