Sure
Sure
Sure
Here are 20 Oracle SQL commands and examples demonstrating the use of the `COMMIT` statement:
1. Basic COMMIT
INSERT INTO employees (employee_id, first_name, last_name)
VALUES (1, 'John', 'Doe');
COMMIT;
BEGIN
INSERT INTO orders (order_id, order_date) VALUES (1, SYSDATE);
DECLARE
CURSOR emp_cursor IS SELECT employee_id, first_name FROM employees;
emp_record emp_cursor%ROWTYPE;
BEGIN
OPEN emp_cursor;
LOOP
FETCH emp_cursor INTO emp_record;
EXIT WHEN emp_cursor%NOTFOUND;
BEGIN
INSERT INTO employees (employee_id, first_name, last_name) VALUES (4, 'Charlie', 'Brown');
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK; -- Undo on error
END;
BEGIN
FOR i IN 1..100 LOOP
INSERT INTO employees (employee_id, first_name, last_name) VALUES (i, 'Employee' || i, 'Last' || i);
END LOOP;
BEGIN
UPDATE employees SET salary = salary * 1.10 WHERE department_id = 30;
UPDATE employees SET salary = salary * 1.05 WHERE department_id = 20;
COMMIT; -- Commit all updates
END;
CREATE OR REPLACE FUNCTION add_employee(emp_id NUMBER, fname VARCHAR2, lname VARCHAR2) RETURN NUMBER IS
BEGIN
INSERT INTO employees (employee_id, first_name, last_name) VALUES (emp_id, fname, lname);
COMMIT; -- Commit within function
RETURN emp_id;
END;
BEGIN
INSERT INTO inventory (item_id, quantity) VALUES (1, 50);
BEGIN
INSERT INTO customers (customer_id, customer_name) VALUES (1, 'Customer A');
INSERT INTO customers (customer_id, customer_name) VALUES (2, 'Customer B');
COMMIT; -- Commit both inserts
END;
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION; -- Declare autonomous transaction
BEGIN
INSERT INTO audit_log (log_id, message) VALUES (1, 'Transaction started');
COMMIT; -- Commit independently
END;
BEGIN
CREATE TABLE department_log (log_id NUMBER, log_message VARCHAR2(100));
CREATE TABLE employee_log (log_id NUMBER, log_message VARCHAR2(100));
COMMIT; -- Commit after DDL statements
END;
BEGIN
INSERT INTO employees (employee_id, first_name, last_name) VALUES (5, 'David', 'Clark');
COMMIT; -- Commit if no errors
EXCEPTION
WHEN OTHERS THEN
ROLLBACK; -- Undo if there is an error
END;