CREATE TABLE test AS
SELECT object_id, object_name, status, created
FROM all_objects;
CREATE TABLE test_hist AS
SELECT object_id, object_name, status, created,
CAST (NULL as VARCHAR2(1)) oper,
CAST (NULL as TIMESTAMP) modified_date
FROM test
WHERE 1 = 0;
CREATE OR REPLACE TRIGGER audit_test
AFTER UPDATE
ON TEST
FOR EACH ROW
DECLARE
/**********************************************************************
NAME: Test
PURPOSE:
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ----------------------------
1.0 5/16/2012 dbolton 1. Created this trigger.
NOTES:
*********************************************************************/
BEGIN
IF ( (:NEW.object_id <> :OLD.object_id)
OR (:NEW.object_name <> :OLD.object_name)
OR (:NEW.status <> :OLD.status)
OR (:NEW.created <> :OLD.created))
THEN
INSERT INTO test_hist
(object_id,
object_name,
status,
created,
oper,
modified_date)
VALUES (:OLD.object_id,
:OLD.object_name,
:OLD.status,
:OLD.created,
'U',
SYSTIMESTAMP);
END IF;
END audit_test;
/
SELECT COUNT (*)
FROM test_hist;
UPDATE test
SET object_name = SUBSTR( object_name, 1, 29) || '-'
WHERE MOD(object_id, 10) = 0;
SELECT COUNT (*)
FROM test_hist;
SET AUTOTRACE ON
UPDATE test
SET object_name = SUBSTR( object_name, 1, 29) || '-'
WHERE MOD(object_id, 10) = 0;
ROLLBACK;
ALTER TRIGGER audit_test DISABLE;
UPDATE test
SET object_name = SUBSTR( object_name, 1, 29) || '-'
WHERE MOD(object_id, 10) = 0;
DROP TRIGGER audit_test;
DROP TABLE test_hist PURGE;
DROP TABLE test PURGE;