user1520344
user1520344

Reputation: 17

oracle trigger select updated row

I'm trying to build a trigger which takes the specific updated row and insert it into another table, but I'm not able to build it.

This is what I was able to build:

CREATE OD REPLACE TRIGGER Z_ONUPDATELOGIN
AFTER UPDATE OF LAST_LOGGED_IN_DATE ON CMN_SEC_USERS csu
BEGIN
  INSERT INTO Z_LOGIN (name, login_date) 
    select first_name||last_name, 
           last_logged_in_date 
      from cmn_sec_users usr 
     where usr.id=csu.id;
END;

Upvotes: 1

Views: 2299

Answers (1)

mucio
mucio

Reputation: 7119

When you deal with triggers you can use the :NEW and :OLD keyword to work with the new and old values of the row you are modifying. In your case try this:

CREATE OR REPLACE TRIGGER Z_ONUPDATELOGIN
  AFTER UPDATE OF LAST_LOGGED_IN_DATE ON CMN_SEC_USERS
  FOR EACH ROW
BEGIN
    INSERT INTO Z_LOGIN (name, login_date) 
    VALUES (:NEW.first_name || :NEW.last_name, 
            :NEW.last_logged_in_date);  
END;

Upvotes: 3

Related Questions