0

我正在尝试创建一个触发器,该触发器将记录审计表中表的任何删除

触发器如下所示:

create or replace TRIGGER cusdelete
AFTER
DELETE OR UPDATE
ON CUSTOMER
DECLARE
v_username varchar2(10);

BEGIN
SELECT V('APP_USER')
INTO v_username
FROM dual;

-- Insert record into audit table
INSERT INTO cusudit
( CUSTOMER_id,
country,
first_name,
last_name,
birth_date,
address,)
VALUES
(old.CUSTOMER_id,
old.country,
old.first_name,
old.last_name,
old.birth_date,
old.address,
sysdate,
v_username );

END;​

但是,当我尝试保存和编译它时,我收到以下消息:

*Compilation failed, line 20 (15:29:04) The line numbers associated with compilation errors are relative to the first BEGIN statement. 
    This only affects the compilation of database triggers.

PLS-00049: bad bind variable 'OLD.QUANTITY'Compilation failed, line 21 (15:29:04) 
    The line numbers associated with compilation errors are relative to the first BEGIN statement. 
    This only affects the compilation of database triggers.

PLS-00049: bad bind variable 'OLD.COST_PER_ITEM'Compilation failed, line 22 (15:29:04)
    The line numbers associated with compilation errors are relative to the first BEGIN statement. 
    This only affects the compilation of database triggers.
PLS-00049: bad bind variable 'OLD.TOTAL_COST'*
4

2 回答 2

1

与编译错误相关的行号是相对的”文本只是告诉您从BEGIN语句开始计算行数,而不是从create or replace trigger.

真正的问题是表中不存在列Quantity、、Cost_Per_Item和。它们看起来不像客户类型的值;他们在另一张桌子上吗?请注意,引用没有导致错误。Total_CostCustomer:old.CUSTOMER_id

附录:另外,请参阅下面的评论,其中@AlexPoole 指出要插入的表是orders_audit,这可能意味着触发器是针对Orders表而不是Customers表的。

于 2013-05-16T15:23:57.727 回答
0

你可以使用 oracle 审计

audit delete on customer

并查询审计跟踪表

select * from dba_audit_trail
于 2013-05-16T17:06:21.597 回答