I have one table called event, and created another global temp table tmp_event with the same columns and definition with event. Is it possible to insert records in event to tmp_event using this ?
DECLARE
v_record event%rowtype;
BEGIN
Insert into tmp_event values v_record;
END;
There are too many columns in event table, I want to try this because I don't want to list all the columns.
Forget to mention: I will use this in the trigger, can this v_record be the object :new after insert on EVENT table ?
There is a way to insert multiple rows into table with %Rowtype.
checkout below example.
To insert one row-
Or a more elaborate version to insert all rows from
event
-In a trigger, yes it is possible but its like the chicken or the egg. You have to initialize every field of the
rowtype
with the:new
column values like-Apparently, the PLSQL examples above cannot be used in a trigger since it would throw a mutating trigger error. And there is no other way for you to get the entire row in the trigger other than accessing each column separately as I explain above, so if you do all this why not directly use
:new.col
in theINSERT into temp_event
itself, will save you a lot of work.Also since you say it's a lot of work to mention all the columns, (in Oracle 11gR2) here's a quick way of doing that by generating the
INSERT
statement and executing it dynamically (although not tested for performance).