CREATE OR REPLACE TRIGGER customers_audit_trg
AFTER
UPDATE OR DELETE
ON customers
FOR EACH ROW
DECLARE
l_transaction VARCHAR2(10);
BEGIN
-- determine the transaction type
l_transaction := CASE
WHEN UPDATING THEN 'UPDATE'
WHEN DELETING THEN 'DELETE'
END;
-- insert a row into the audit table
INSERT INTO audits (table_name, transaction_name, by_user, transaction_date)
VALUES('CUSTOMERS', l_transaction, USER, SYSDATE);
END;
/
Code language: SQL (Structured Query Language) (sql)