Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

insert multiple rows in trigger ?

708631Oct 20 2014 — edited Oct 21 2014

can anyone tell me how I can insert multiple rows in a trigger. I have tried multiple ways and so far nothing works.

create or replace

TRIGGER USER_GROUPS_TRIG

before INSERT ON USER_GROUPS

FOR EACH ROW

DECLARE   

max_id number;

BEGIN

SELECT TO_NUMBER(new_id ) +1 as new_id into max_id FROM NEW_ID_VW;

INSERT INTO   TBL1

    (USER, NAME)  VALUES

    (max_id ,   :NEW.NEW); --this works fine and needs no adjustment, 1 row inserted.

   

   

MERGE INTO GROUP_MAPPING A

USING (SELECT USER_ID,GROUP_ID FROM ADMIN_GROUPS_VW) B

  ON (A.USER_ID=B.USER_ID)

  WHEN NOT MATCHED THEN

    INSERT (A.USER_ID,A.GROUP_ID)

    values (b.user_id,b.group_id);

 

  --FOR V IN 1..10 LOOP

   -- INSERT INTO GROUP_MAPPING  (user_id,group_id)

   -- (select user_id,group_id from admin_groups_vw);

-- END LOOP;

--INSERT INTO GROUP_MAPPING

   -- (USER_ID, GROUP_ID) VALUES

--(max_id ,(select group_id from admin_groups_vw));

  

     --none of these pop an error, just doesnt do the insert (there is multiple records so there should be multipe rows inserted) , i tried insert, loop, and merge.

   

END;

Thanks for any help.

This post has been answered by Frank Kulash on Oct 20 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2014
Added on Oct 20 2014
11 comments
2,884 views