【发布时间】:2021-04-05 02:08:03
【问题描述】:
问题:创建一个名为 trg_job_date 的触发器,它将在插入或更新时将作业表中的 JOB_LAST_UPDATE 列更新为当前日期。使用插入和更新语句测试触发器 - 包括插入和更新语句。
所以我试图通过触发器更新工作中的job_last_update,但我读到我可以在触发器中拥有我想要更新的同一张表。我的主要问题是job_last_update 仅在作业表中可用。
到目前为止,这是我的代码:
create or replace trigger trg_job_date
after insert or update
on job
for each row
begin
update job
set job_last_update = current_date;
end;
insert into job (job_code, job_description, job_chg_hour, job_last_update)
values('511', 'Hardware management', '22.11', '4/4/2021');
update job
set job_description = 'Hardware Manager'
where job_code = 511;
select * from job; --using this to test whether the trigger worked properly
触发器运行没有问题,但是当我尝试运行我的插入语句时,它给了我错误:
ORA-04091: table SQL_IUARPVSJLXIJWEVKOWRJRCSXZ.JOB is mutating, trigger/function may not see it ORA-06512: at "SQL_IUARPVSJLXIJWEVKOWRJRCSXZ.TRG_JOB_DATE", line 2
ORA-06512: at "SYS.DBMS_SQL", line 1721
我需要做什么才能让我的代码做我需要做的事情?
【问题讨论】:
-
从不将日期/时间值存储为字符串,这是一个设计缺陷。使用 DATE 值。