简体   繁体   English

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

[英]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;
  1. Use DEFAULT SYSDATE on the colum date_created like already suggested 像已经建议的那样对date_created使用DEFAULT SYSDATE
  2. if you insist to use a trigger, just write :NEW.date_created := SYSDATE; 如果您坚持使用触发器,只需编写:NEW.date_created := SYSDATE;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建正确的触发器而不是插入或更新? ORACLE。 扳机。 pl/sql - How to create the correct trigger instead of insert or update? ORACLE. Trigger. pl/sql 如何在SQL中对触发器进行语法化处理以便更新同一表中的列AFTER INSERT(Oracle Database) - How to syntax a trigger in SQL in order to UPDATE a column from the same table AFTER INSERT (oracle Database) 创建触发器的问题。 每个表中的列名必须是唯一的。 微软SQL - Problem with creating trigger. Column names in each table must be unique. MsSQL SQL Server2012。触发器。 创建表时如何自动创建触发器 - SQL Server 2012. Trigger. How to automatically create trigger when table created 在Oracle表上创建ON INSERT触发器 - Creating ON INSERT trigger on Oracle table Oracle触发器插入其他表 - Oracle trigger insert other table 使用“ AFTER INSERT,UPDATE,DELETE” DML触发器。 如何引用触发行? - Using “AFTER INSERT, UPDATE, DELETE” DML trigger. How reference triggering row? 如何通过在ORACLE中插入INSERT时提取另一列来创建触发器? - How to create a trigger, by extracting form another column in the time of INSERT in ORACLE? MySQL触发器。 如何在有限的时间内存储表中的每一行数据? - MySQL trigger. How to store each row of data in table for a limited time? 触发器中的数字到字符转换错误。 [甲骨文11G] - Number to character conversion error in trigger. [ORACLE 11G ]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM