[英]How to insert date in a table column with a trigger. (ORACLE)
Essentially I wish to create a trigger that keeps track and edits the date_created
column of a specific row after every insert or update. 本质上,我希望创建一个触发器,以在每次插入或更新后跟踪并编辑特定行的date_created
列。
These are the columns in my table: 这些是我表中的列:
| customer_id | store_id | Quantity | date_created |
the customer_id and store_id together are the primary key of the table customer_id和store_id一起是表的主键
What I have so far: 到目前为止,我有:
CREATE OR REPLACE TRIGGER date_trig
BEFORE INSERT ON customer_table
FOR EACH ROW
DECLARE
BEGIN
-- This is where I assume the date will be set or edited
END;
I am brand new to PL/SQL so I am struggling with the actual body of this trigger. 我是PL / SQL的新手,所以我为该触发器的实际内容而苦苦挣扎。
Also, do I have the structure of a trigger correctly formed? 另外,我是否正确形成了触发器的结构?
Hi Please find sample code. 嗨,请找到示例代码。
create or replace trigger emp_mod_date
before update or insert on emp
for each row
begin
:new.mdate := sysdate;
end;
DEFAULT SYSDATE
on the colum date_created
like already suggested 像已经建议的那样对date_created
使用DEFAULT SYSDATE
:NEW.date_created := SYSDATE;
如果您坚持使用触发器,只需编写:NEW.date_created := SYSDATE;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.