Transactions and Error Handling : Transaction Rollback Commit « Table « Oracle PL / SQL






Transactions and Error Handling

    
SQL>
SQL> CREATE TABLE emp (
  2     empID INT NOT NULL PRIMARY KEY,
  3     Name      VARCHAR(50) NOT NULL);

Table created.

SQL> INSERT INTO emp (empID,Name) VALUES (1,'Tom');

1 row created.

SQL> INSERT INTO emp (empID,Name) VALUES (2,'Jack');

1 row created.

SQL> INSERT INTO emp (empID,Name) VALUES (3,'Mary');

1 row created.

SQL> INSERT INTO emp (empID,Name) VALUES (4,'Bill');

1 row created.

SQL> INSERT INTO emp (empID,Name) VALUES (5,'Cat');

1 row created.

SQL> INSERT INTO emp (empID,Name) VALUES (6,'Victor');

1 row created.

SQL> BEGIN
  2
  3     INSERT INTO emp (empID, Name) VALUES (101, 'java2s');
  4     INSERT INTO emp (empID, Name) VALUES (102, 'Claire');
  5
  6     SAVEPOINT BeforeAddingAnne;
  7     INSERT INTO emp (empID, Name) VALUES (103, 'Anne');
  8     ROLLBACK TO BeforeAddingAnne;
  9
 10     COMMIT;
 11
 12  EXCEPTION
 13     WHEN OTHERS
 14        THEN ROLLBACK;
 15  END;
 16  /

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> drop table emp;

Table dropped.

   
    
    
    
  








Related examples in the same category

1.Transaction Rollback and commit
2.atomicity: roll back and commit
3.Rollback a delete
4.TRANSACTION CONTROL
5.set transaction use rollback segment SEGMENT_NAME
6.show autocommit
7.Transactions and Savepoints
8.SET TRANSACTION READ WRITE
9.Rollback to savepoint in exception handler
10.alter rollback segment SEGMENT_NAME online