我正在尝试创建一个触发器,用于记录审计表中表的任何删除
触发器如下所示:
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'*
答案 0 :(得分:1)
与编译错误相关联的“行号是相对的”文本只是告诉您从BEGIN
语句开始而不是从create or replace trigger
开始计算行。
真正的问题是Quantity
表中不存在列Cost_Per_Item
,Total_Cost
和Customer
。它们看起来不像客户类型的价值;他们在另一张桌子上吗?请注意,:old.CUSTOMER_id
引用不会导致错误。
附录:另外,请参阅下面的评论,其中@AlexPoole指出要插入的表格是orders_audit
,这可能意味着触发器是针对{{1表而不是Orders
表。
答案 1 :(得分:0)
你可以使用oracle audit
audit delete on customer
并查询审计跟踪表
select * from dba_audit_trail