Expert

Q:

11-25.

You can either use dynamic SQL (DBMS_SQL prior to Oracle 8.1 or native dynamic SQL from 8.1 onwards) to execute a dynamic PL/SQL block. You can also take advantage of the SAVEPOINT procedure in the DBMS_STANDARD package as shown in this rewrite:

BEGIN
   DBMS_STANDARD.SAVEPOINT ('start_process');
   INSERT INTO ...;
   DELETE FROM ...;

Q:

11-26.

You can set a savepoint in any of these ways:

  • SAVEPOINT savepoint;

  • DBMS_TRANSACTION.SAVEPOINT savepoint;

  • DBMS_STANDARD.SAVEPOINT savepoint;

  • Through the use of DBMS_SQL

Q:

11-27.

You can roll back your transaction in PL/SQL in any of these ways:

  • ROLLBACK;

  • DBMS_TRANSACTION.ROLLBACK_SAVEPOINT savepoint;

  • DBMS_STANDARD.ROLLBACK_SV savepoint;

  • Dynamic SQL (DBMS_SQL or native dynamic SQL in Oracle 8.1)

  • Unhandled exception

Q:

11-28.

When you execute this code, you get the following error:

ORA-01086: savepoint 'START_PROCESS' never established

At first glance this doesn’t make sense. You set the savepoint and then try to roll back to that savepoint. Unfortunately, Oracle doesn’t consider them to be the same savepoint. If you are going to set a savepoint by using the DBMS_STANDARD.SAVEPOINT program, you must roll back to that savepoint by calling another DBMS_STANDARD program:

BEGIN
   DBMS_STANDARD.SAVEPOINT ('start_process');
   DBMS_STANDARD.ROLLBACK_SV ('start_process');
END;

Q:

11-29.

Each time you issue a COMMIT in your session, the rollback segment is set back to the default for your session. You must, therefore, be careful to reset the current rollback segment back ...

Get Oracle PL/SQL Programming: A Developer's Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.