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