Skip to content
Advertisement

Getting error while assigning value to collection variable

procedure ins_note (pi_data in note_detail_arr)   

is 
begin

   FOR i IN pi_data.first..pi_data.last loop

    IF pi_data(i).template_id IN (022, 019, 015, 017, 021, 001, 010, 016, 018, 020, 023) AND pi_data(i).channel_id IS NULL THEN
        pi_data(i).channel_id := 'XLS';
    END IF;
      INSERT INTO note_msg (template_id,channel_id)                                                      
                                VALUES (
                                 pi_data(i).template_id, pi_data(i).channel_id);                  
                     end loop;
commit;
end;              

Advertisement

Answer

pi_data is a an array of elements that is an IN argument. You cannot assign values to IN argument. Declare a local variable to store the channel_id, or declare a local variable of type note_msg%ROWTYPE and use that instead for storing channel id. You have not mentioned what the declaration is of note_detail_arr so I’m defining a local variable of ROWTYPE. Example:

procedure ins_note(pi_data IN note_detail_arr) 
is 
  l_note_msg_row note_msg%ROWTYPE;
BEGIN
  FOR i IN pi_data.first..pi_data.last LOOP
    l_note_msg_row.channel_id := pi_data(i).channel_id;
    IF
      pi_data(i).template_id IN (022, 019, 015, 017, 021, 001, 010, 016, 018, 020, 023 ) AND pi_data(i).channel_id IS NULL
    THEN
      l_note_msg_row.channel_id := 'XLS';
    END IF;

    INSERT INTO note_msg (
      template_id,
      channel_id
    ) VALUES (
      pi_data(i).template_id,
      l_note_msg_row.channel_id
    );

  END LOOP;
  -- you should not commit in your procedure. Instead only commit when your complete transaction is done from code that calls this proc.
  COMMIT;   
END ins_note;
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement