簡體   English   中英

如何使用觸發器在表列中插入日期。 (ORACLE)

[英]How to insert date in a table column with a trigger. (ORACLE)

本質上,我希望創建一個觸發器,以在每次插入或更新后跟蹤並編輯特定行的date_created列。

這些是我表中的列:

| customer_id | store_id | Quantity | date_created |

customer_id和store_id一起是表的主鍵

到目前為止,我有:

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;

我是PL / SQL的新手,所以我為該觸發器的實際內容而苦苦掙扎。

另外,我是否正確形成了觸發器的結構?

嗨,請找到示例代碼。

create or replace trigger emp_mod_date
before update or insert on emp
for each row
begin
 :new.mdate := sysdate;
end;
  1. 像已經建議的那樣對date_created使用DEFAULT SYSDATE
  2. 如果您堅持使用觸發器,只需編寫:NEW.date_created := SYSDATE;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM