Using savepoint, PL-SQL Programming

Assignment Help:

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.


Related Discussions:- Using savepoint

Appgen to sap data export, We are seeking a freelance consultant that is fa...

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

Avoid the not null constraint - performance of application, Avoid the NOT N...

Avoid the NOT NULL Constraint In the PL/SQL, using the NOT NULL constraint incur a performance cost. Consider the illustration as shown below: PROCEDURE calc_m IS m NUMB

In mode - parameter modes, IN Mode An IN parameter pass the values to ...

IN Mode An IN parameter pass the values to the subprogram being called. Within the subprogram, an IN parameter acts like a constant. And hence, it cannot be assigned a value.

For-loop -iterative control, FOR-LOOP While the number of iterations thr...

FOR-LOOP While the number of iterations through a WHILE loop is unknown till the loop completes, then the number of iterations through a FOR loop is known before the loop is ent

Conditionals - sql, Conditionals - SQL At first sight SQL does not app...

Conditionals - SQL At first sight SQL does not appear to have a single operator for expressing logical implication. In this respect it would be in common with most programming

Create a procedure to tax calculation task, Complete the following steps to...

Complete the following steps to create a procedure to calculate the tax on an order. The BB_TAX table contains the states that require taxes to be submitted for Internet sales. If

Using operator value in pl sql, Using Operator VALUE: As you may expec...

Using Operator VALUE: As you may expect, the operator VALUE returns the value of an object. The VALUE takes its argument a correlation variable.  For illustration, to return a

Using aliases-declarations in sql, Using Aliases The Select-list items f...

Using Aliases The Select-list items fetched from a cursor related with the %ROWTYPE should have simple names or, if they are expressions, should have aliases. In the example bel

Fetching across commits, Fetching Across Commits The FOR UPDATE clause...

Fetching Across Commits The FOR UPDATE clauses acquire exclusive all row locks. All rows are locked when you open the cursor, and when you commit your transaction they are unl

Currval and nextval - sql pseudocolumns, CURRVAL and NEXTVAL The serie...

CURRVAL and NEXTVAL The series is a schema object which generates the sequential numbers. Whenever you form a sequence, you can specify its primary value and an increment. T

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd