CompScientist
CompScientist

Reputation: 21

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.

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

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.

Also, do I have the structure of a trigger correctly formed?

Upvotes: 0

Views: 7148

Answers (2)

vishnu sable
vishnu sable

Reputation: 358

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;

Upvotes: 1

Olli
Olli

Reputation: 729

  1. Use DEFAULT SYSDATE on the colum date_created like already suggested
  2. if you insist to use a trigger, just write :NEW.date_created := SYSDATE;

Upvotes: 0

Related Questions