title: Oracle Trigger After Insert
body: <p>I have a messages table. After an insert on messages, I need to insert the UserID and MsgID from that insert into the messageRecipient table. If the message was sent to a group, it needs to be inserted to every user that is a member of that group. Here is what I have, but it is not inserting into the messageRecipient table:</p>
  
  <pre><code>create or replace trigger update_messages
  after insert on messages referencing new as new old as old  
  for each row
  declare 
        userID1 int(10);
        msgID1 int(10);
        groupID1 int(10);
  begin
        userID1 := :new.ToUserID;
        msgID1 := :new.msgID;
        groupID1 := :new.ToGroupID;
  
       if inserting then
              if(userID1 &lt;&gt; null)
                  then INSERT INTO messageRecipient VALUES(msgID1, userID1);
              elsif(groupID1 &lt;&gt; null)
                  THEN INSERT INTO messageRecipient(msgID, userID) SELECT msgID1, userID FROM groupMembership WHERE gID = groupID1;
              end if;
       end if; 
  end;
  /
  </code></pre>
  
  <p>What exactly is going wrong here?</p>