TCL (Transaction Control Language)
Last updated
BEGIN
INSERT INTO Orders (OrderID, CustomerID, OrderDate) VALUES (2023051402, 1002, SYSDATE);
INSERT INTO OrderItems (OrderID, ProductID, Quantity) VALUES (2023051402, 5678, 10);
ROLLBACK;
END;SAVEPOINT savepoint_name;-- Start a transaction
BEGIN
-- Update first_name for employee with ID 1001
UPDATE employees SET first_name = 'John' WHERE employee_id = 1001;
-- Create a savepoint
SAVEPOINT before_update_1002;
-- Update first_name for employee with ID 1002
UPDATE employees SET first_name = 'Jane' WHERE employee_id = 1002;
-- Commit the transaction
COMMIT;
EXCEPTION
-- Handle exceptions
WHEN OTHERS THEN
-- Rollback to savepoint if an error occurs
ROLLBACK TO before_update_1002;
-- Handle the error (print error message, log, etc.)
DBMS_OUTPUT.PUT_LINE('An error occurred. Rolling back to savepoint.');
END;SET TRANSACTION [isolation_level] [other_parameters];-- Setting transaction isolation level to READ COMMITTED
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;