CREATE OR REPLACE TRIGGER trg_placement
AFTER INSERT OR DELETE OR UPDATE
ON lds_placement
FOR EACH ROW
ENABLE
DECLARE
v_user VARCHAR2(30);
v_date VARCHAR2(30);
BEGIN
SELECT USER, TO_CHAR(SYSDATE, 'DD/MON/YYYY HH24:MI:SS')
INTO v_user, v_date
FROM DUAL;
IF INSERTING
THEN
INSERT INTO audit_trial(
placement_id,
new_name,
old_name,
user_name,
audit_date,
audit_operation
)
VALUES (
:NEW.plt_short_desc,
NULL,
v_user,
v_date,
'INSERT'
);
ELSIF DELETING
THEN
INSERT INTO audit_trial(
placement_id,
new_name,
old_name,
user_name,
audit_date,
audit_operation
) -----line 16 is here.statement ignored
VALUES (
NULL,
:OLD.plt_short_desc,
v_user,
v_date,
'DELETE'
);
ELSIF UPDATING
THEN
INSERT INTO audit_trial(
placement_id,
new_name,
old_name,
user_name,
audit_date,
audit_operation
)
VALUES (
:NEW.plt_short_desc,
:OLD.plt_short_desc,
v_user,
v_date,
'UPDATE'
);
END IF;
END trg_placement;
我收到此错误:
第16行出错:PL / SQL:忽略SQL语句
答案 0 :(得分:0)
CREATE OR REPLACE TRIGGER trg_placement
AFTER INSERT OR DELETE OR UPDATE ON lds_placement
FOR EACH ROW
DECLARE
v_user varchar2(30);
v_date varchar2(30);
BEGIN
SELECT user, TO_CHAR(sysdate,'DD/MON/YYYY HH24:MI:SS') INTO v_user,v_date FROM dual;
IF INSERTING
THEN
INSERT INTO audit_trial(placement_id,new_name,old_name,user_name,audit_date ,audit_operation)
VALUES(:old.placement_id,:NEW.plt_short_desc,:OLD.plt_short_desc,v_user,v_date,'UPDATE');
ELSIF DELETING
THEN
INSERT INTO audit_trial(placement_id,new_name,old_name,user_name,audit_date,audit_operation)
VALUES(:OLD.placement_id,:NEW.plt_short_desc,:OLD.plt_short_desc,v_user,v_date,'DELETE');
ELSIF UPDATING
THEN
INSERT INTO audit_trial(placement_id,new_name,old_name,user_name,audit_date ,audit_operation)
VALUES(:OLD.placement_id,:NEW.plt_short_desc,:OLD.plt_short_desc,v_user,v_date,'UPDATE');
END IF;
END trg_placement;
我做了改动,但它正在发挥作用。
我正在尝试将loop语句添加到审计试验中,以便当用户对源表lds_placement中的任何列进行更改时,它将被审计。但是根据我的查询,这个触发器只针对所有列的一列plt_short_desc。请帮助您查询。