Using savepoint, PL-SQL Programming

Using SAVEPOINT

The SAVEPOINT names and marks the present point in the processing of a transaction. Used with the ROLLBACK TO statement, the savepoints undo parts of a transaction rather than the entire transaction. In the illustration below, you mark a savepoint before doing an insert. When the INSERT statement tries to store a duplicate value in the empno column, the predefined exception DUP_VAL_ON_INDEX is raised. In that situation, you roll back to the savepoint, undoing merely the insert.

DECLARE

emp_id emp.empno%TYPE;

BEGIN

UPDATE emp SET ... WHERE empno = emp_id;

DELETE FROM emp WHERE ...

...

SAVEPOINT do_insert;

INSERT INTO emp VALUES (emp_id, ...);

EXCEPTION

WHEN DUP_VAL_ON_INDEX THEN

ROLLBACK TO do_insert;

END;

If you roll back to a savepoint, any savepoints marked after the savepoint are erasing. Though, the savepoint to which you roll back is not erasing. For illustration, if you mark five savepoints, and then roll back to the third, only the fourth and the fifth are erase. A simple rollback or commit erases all savepoints.

When you mark a savepoint within a recursive subprogram, the new instances of the

SAVEPOINT statements are executed at each level in the recursive fall. Though, you can only roll back to the nearly all recently marked savepoint.

The Savepoint names are undeclared identifiers and can be reused within the transaction. This moves the savepoint from its old position to the persent point in the transaction. And hence, the rollback to the savepoint affects only the present part of your transaction. An illustration is as shown:

BEGIN

...

SAVEPOINT my_point;

UPDATE emp SET ... WHERE empno = emp_id;

...

SAVEPOINT my_point; -- move my_point to current point

INSERT INTO emp VALUES (emp_id, ...);

EXCEPTION

WHEN OTHERS THEN

ROLLBACK TO my_point;

END;

The number of active savepoints per session is limitless. An active savepoint is the one marked as the last commit or rollback.

Posted Date: 10/4/2012 5:15:24 AM | Location : United States







Related Discussions:- Using savepoint, Assignment Help, Ask Question on Using savepoint, Get Answer, Expert's Help, Using savepoint Discussions

Write discussion on Using savepoint
Your posts are moderated
Related Questions
Running the PL/SQL Wrapper To run the PL/SQL Wrapper, go through the wrap command at your operating system prompt by using the syntax as shown: wrap iname=input_file [oname=

Sequential Control Dissimilar to the IF and LOOP statements, the GOTO and NULL statements are not important to the PL/SQL programming. The configuration of PL/SQL is such that th

We are seeking a freelance consultant that is familiar with Appgen applications. We require exporting all our data into a format appropriate for importing into SAP Business One. Pl

What Is a Package? The package is a schema object that group logically related PL/SQL items, types, and subprograms. The Packages usually have 2 parts, a specification & a bo

Equivalences & Rewrite Rules: If notice that as well as allowing us to prove trivial theorems, and tautologies enable us to establish that certain sentences are saying the sam

Overloading The PL/SQL overloads the subprogram names. That is, you can use similar name for few different subprograms as long as their formal parameters differ in the number

Parameter and Keyword Description: type_name: This identifies a user-defined type specifier that is used in the subsequent declarations of the objects. AUTHID Clause:

Providing Results of Queries Expressing queries in SQL is the (big) subject. Here I present just a simple example to give you the flavour of things to come in those chapters.

Implicit Cursors The Oracle implicitly opens a cursor to process each SQL statement not related with an explicitly declared cursor. The PL/SQL lets you refer to the most recen

Difference between 9i & 10G When Oracle releases any new databases then it are having some discrepancy with them. But 10G is having much difference than oracle 9i has. Oracle