Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 300
user3547213 Avatar asked Oct 28 '25 11:10

user3547213


1 Answers

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;
/
like image 107
Mureinik Avatar answered Oct 31 '25 03:10

Mureinik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!