user3547213
user3547213

Reputation: 41

Oracle trigger to update a column value in the same table

I am in the need of a trigger which will fire on any insert or updates on the specific table and while inserting or updating will substitute a credit card number column of the new row to something bogus such as "1111 1111 1111 1111"

Here is what I cooked up but it doesn't seem to work.

CREATE or REPLACE TRIGGER trigger_name  AFTER INSERT ON table1
FOR EACH ROW

BEGIN
update table1 set cc_number_field = '11';
END;

I am on Oracle 10 if that matters.

Upvotes: 4

Views: 15291

Answers (2)

EdStevens
EdStevens

Reputation: 3872

Not tested:

CREATE OR REPLACE TRIGGER t BEFORE INSERT on ON table1 FOR EACH ROW begin :new.cc_number_field = '11'; END;

PL/SQL Reference - Triggers

Upvotes: 0

Mureinik
Mureinik

Reputation: 311018

It's much easier to manipulate the incoming :NEW line with a "before" trigger:

CREATE OR REPLACE TRIGGER table1_cc_trigger
BEFORE INSERT OR UPDATE ON table1
FOR EACH ROW
BEGIN
    :NEW.cc_number_field := '1111 1111 1111 1111';
END;
/

Upvotes: 10

Related Questions