如果要监测的表没几张,同时这个表的dml操作不是很大,加trigger在数据库层面是可以实现的。如果这个表的dml量很大,那么这个trigger 就是你性能的瓶颈,所以要合理考虑后再使用。我认为用其监测参数表还是不错的。
PHP code:
CREATE OR REPLACE TRIGGER "QIUYB".TRA_TP_TRUNK
AFTER INSERT OR UPDATE OR DELETE ON TP_TRUNK
FOR EACH ROW
BEGIN
IF INSERTING THEN
INSERT INTO QIUYB_OPERATE_HISTORY
VALUES
('tp_trunk',
SYS_CONTEXT('userenv', 'session_user'),
SYS_CONTEXT('userenv', 'ip_address'),
SYS_CONTEXT('userenv', 'host'),
TO_CHAR(SYSDATE, 'YYYYMMDDHHMMSS'),
'INSERT',
:NEW.SWITCH_CODE || ',' || :NEW.TRUNK_CODE || ',' || :NEW.TRUNK_SIDE || ',' ||
:NEW.TRUNK_TYPE || ',' || :NEW.START_DATE || ',' || :NEW.END_DATE || ',' ||
:NEW.COMMENTS);
ELSIF UPDATING THEN
INSERT INTO QIUYB_OPERATE_HISTORY
VALUES
('tp_trunk',
SYS_CONTEXT('userenv', 'session_user'),
SYS_CONTEXT('userenv', 'ip_address'),
SYS_CONTEXT('userenv', 'host'),
TO_CHAR(SYSDATE, 'YYYYMMDDHHMMSS'),
'UPDATE',
:OLD.SWITCH_CODE || ',' || :OLD.TRUNK_CODE || ',' || :OLD.TRUNK_SIDE || ',' ||
:OLD.TRUNK_TYPE || ',' || :OLD.START_DATE || ',' || :OLD.END_DATE || ',' ||
:OLD.COMMENTS || '->' || :NEW.SWITCH_CODE || ',' || :NEW.TRUNK_CODE || ',' ||
:NEW.TRUNK_SIDE || ',' || :NEW.TRUNK_TYPE || ',' || :NEW.START_DATE || ',' ||
:NEW.END_DATE || ',' || :NEW.COMMENTS);
ELSE
INSERT INTO QIUYB_OPERATE_HISTORY
VALUES
('tp_trunk',
SYS_CONTEXT('userenv', 'session_user'),
SYS_CONTEXT('userenv', 'ip_address'),
SYS_CONTEXT('userenv', 'host'),
TO_CHAR(SYSDATE, 'YYYYMMDDHHMMSS'),
'DELETE',
:OLD.SWITCH_CODE || ',' || :OLD.TRUNK_CODE || ',' || :OLD.TRUNK_SIDE || ',' ||
:OLD.TRUNK_TYPE || ',' || :OLD.START_DATE || ',' || :OLD.END_DATE || ',' ||
:OLD.COMMENTS);
END IF;
END TRA_TP_TRUNK;