title: Call to the function failing with : ORA-00904: "TEMP_DATA"."P_LNAME": invalid identifier
body: <p>The following function compiles fine. But when a call is made to the function in an anonymous PL/SQL code, the call fails.
  Can anyone please suggest why ? I am trying to insert the un-matched (new) data and update the matching (existing) data.</p>
  
  <pre><code>Function Fn_Insert_Data_Using_Merge (p_Id in Number,
                                       p_fname in varchar2,
                                       p_mname in varchar2,
                                       p_lname in varchar2,
                                       p_birth_date in date) Return Boolean
  Is
  Begin
    Dbms_Output.put_line ('Inside the function Fn_Insert_Data_Using_Merge ...');
    Merge Into test_employee te
      using (select distinct p_Id, p_fname, p_mname, p_lname, p_birth_date
               from test_employee) temp_data
      on (te.first_name = temp_data.p_fname and
          te.middle_name = temp_data.p_mname and
          te.last_name = temp_data.p_lname)
      when matched then 
        update
          set first_name = p_fname,
              middle_name = p_mname,
              last_name = p_lname,
              run_status = 'Updated'
      when not matched then
        insert (id, first_name, middle_name, last_name, birth_date, run_status)
          values
               (p_id, p_fname, p_mname, p_lname, p_birth_date, 'Inserted');
  
    Dbms_Output.put_line ('Returning successfully from the function Fn_Insert_Data_Using_Merge ...');
    Return True;
  Exception
    When Dup_Val_On_Index Then
      Dbms_Output.put_line ('The name already exists...Cannot insert again ..');
      Return False;
    When Others Then
      Dbms_Output.put_line ('Facing some critical error : ' || SQLERRM);
      Return False;
  End Fn_Insert_Data_Using_Merge;
  </code></pre>