Home >> FAQs/Tutorials >> Oracle Tutorials

Oracle Tutorials - Transaction Rollback When Session Killed

By: FYIcenter.com

(Continued from previous topic...)

What Happens to the Current Transaction If the Session Is Killed?

If a session is killed by the DBA, the current transaction in that session will be rolled back and ended. All the database changes made in the current transaction will be removed. This is called an implicit rollback when session is killed. The following tutorial exercise shows you that the DBA KILL SESSION command forces the current transaction to be rolled back with all the changes uncommitted.

SQL> connect HR/fyicenter

SQL> SELECT * FROM fyi_links;
     ID URL              NOTES          COUNTS CREATED
------- ---------------- ---------- ---------- ---------
    101 FYICENTER.COM                          07-MAY-06
    110 CENTERFYI.COM                          07-MAY-06
    112 oracle.com                             07-MAY-06
    113 sql.com                                07-MAY-06

SQL> DELETE FROM fyi_links where id = 112;
1 row deleted.

SQL> DELETE FROM fyi_links where id = 113;
1 row deleted.

SQL> SELECT * FROM fyi_links;
     ID URL              NOTES          COUNTS CREATED
------- ---------------- ---------- ---------- ---------
    101 FYICENTER.COM                          07-MAY-06
    110 CENTERFYI.COM                          07-MAY-06

Keep the "HR" SQL*Plus window as is, and open another window to run another instance of SQL*Plus.

>cd (OracleXE home directory)
>.\bin\sqlplus /nolog

SQL> connect SYSTEM/password
Connected.

SQL> SELECT sid, serial#, username, status, type
  2  FROM V$SESSION WHERE username = 'HR';
       SID    SERIAL# USERNAME           STATUS   TYPE
---------- ---------- ------------------ -------- -----
        39        141 HR                 INACTIVE USER

SQL> ALTER SYSTEM KILL SESSION '39,141';
System altered.

Go back to the "HR" SQL*Plus window.

SQL> SELECT * FROM fyi_links;
ORA-00028: your session has been killed

SQL> connect HR/fyicenter

SQL> SELECT * FROM fyi_links;
     ID URL              NOTES          COUNTS CREATED
------- ---------------- ---------- ---------- ---------
    101 FYICENTER.COM                          07-MAY-06
    110 CENTERFYI.COM                          07-MAY-06
    112 oracle.com                             07-MAY-06
    113 sql.com                                07-MAY-06

As you can see, two records were rolled back as the session got killed by another session.

(Continued on next topic...)

  1. What Is a Transaction?
  2. How To Start a New Transaction?
  3. How To End the Current Transaction?
  4. How To Create a Test Table for Transaction Testing?
  5. How To Commit the Current Transaction?
  6. How To Rollback the Current Transaction?
  7. What Happens to the Current Transaction If a DDL Statement Is Executed?
  8. What Happens to the Current Transaction If the Session Is Ended?
  9. What Happens to the Current Transaction If the Session Is Killed?
  10. How Does Oracle Handle Read Consistency?
  11. What Is a READ WRITE Transaction?
  12. What Is a READ ONLY Transaction?
  13. How To Set a Transaction To Be READ ONLY?
  14. What Are the Restrictions in a READ ONLY Transaction?
  15. What Are the General Rules on Data Consistency?
  16. What Are Transaction Isolation Levels Supported by Oracle?
  17. What Is a Data Lock?
  18. How Data Locks Are Respected?
  19. How To Experiment a Data Lock?
  20. How To View Existing Locks on the Database?
  21. What Is a Dead Lock?
  22. How Oracle Handles Dead Locks?

Oracle Tutorials:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...