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

I need sql - wp sql expert, I need SQL , WP SQL Expert Project Descripti...

I need SQL , WP SQL Expert Project Description: Expert required to modify WP SQL query. Skills required are MySQL, SQL, PHP, Wordpress

Insert statement - syntax, INSERT Statement The INSERT statement adds f...

INSERT Statement The INSERT statement adds fresh rows of data to the specified database table or view. Syntax:

Advantages of pl/sql, Advantages of PL/SQL The PL/SQL is a high-perform...

Advantages of PL/SQL The PL/SQL is a high-performance transaction processing, completely portable language that offers the following advantages as shown: 1) Support for SQL

Pass the nulls to a dynamic sql, Pass the nulls to a dynamic SQL: Pas...

Pass the nulls to a dynamic SQL: Passing Nulls: Assume that you want to pass the nulls to a dynamic SQL statement. For illustration, you may write the EXECUTE IMMEDIATE

Iteration schemes- iterative control, Iteration Schemes The bounds of a ...

Iteration Schemes The bounds of a loop range can be variables, literals, variables, or expressions but must compute to integers. Below are some of the examples. As you can see t

An active database in pl-sql, Consider the following set of database tables...

Consider the following set of database tables (same tables from Assignment 6-1). Please take note of foreign keys (most of them carry the same names as the corresponding primary ke

Heap sort algorithm in pl sql, I want to implement heap sort algorithm in p...

I want to implement heap sort algorithm in pl sql please share the source code for guidance

Introduction to SQl and DQL, which operation is used if we are interested i...

which operation is used if we are interested in only certain columns of a table?

How transactions guard your database, How Transactions Guard Your Database ...

How Transactions Guard Your Database The transaction is a sequence of SQL data manipulation statements which does a logical unit of work. The Oracle treats the sequence of SQL

Use of count in sql, Use of COUNT in SQL It describes and discusses va...

Use of COUNT in SQL It describes and discusses various general methods of expressing constraints, eventually noting that support for "=" with relation operands is sufficient f

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