MFriend
MFriend

Reputation: 21

Insert data into a different column when copying from one table to another in Oracle

I am using an AFTER INSERT row trigger in Oracle 11g to copy specific columns from one table to another on insert. I have the trigger and insert working ok. The problem I have is that I need to insert the new data from one column to a different column when copying it.

The trigger info reads:

BEGIN
 insert into BALES_STORAGE 
               (CROP, 
               CUTTING, 
               DESTINATION, 
               BALES_MOVED, 
               DATE_MOVED, 
               PASTURE, 
               TARGET_LB_PER_DAY)
 values 
               (:new.CROP, 
               :new.CUTTING, 
               :new.MOVING_LOCATION, 
               :new.BALES_MOVED, 
               :new.DATE_MOVED, 
               :new.PASTURE, 
               :new.TARGET_LB_PER_DAY);
END;

The first table is called "BALES_HARVESTED" and the 2nd table the trigger inserts the selected columns into is called "BALES_STORAGE". I need to insert the :new.MOVING_LOCATION data into the column called DESTINATION on the second table.

So my question is: when using an after insert row trigger, how to I change the column that the data is inserted into?

Thanks for any help.

Matthew

Upvotes: 2

Views: 498

Answers (1)

Joshua Huber
Joshua Huber

Reputation: 3533

Your trigger code worked just fine for me. Not sure what the problem is. The 3rd column in your INSERT statement does the column mapping correctly.

http://sqlfiddle.com/#!4/2d2fd5/1/1

Maybe you have different structures or foreign key constraints. Could you elaborate on what error you get? Does it produce an ORA- error? or does it simply not produce the desired result, but no error?

Upvotes: 0

Related Questions