Search code examples
oracle-databasemergevarray

In Oracle Can i refer a VARRAY in MERGE syntax this way?


The following produces a error: [Error] ORA-00904 (265: 19): PL/SQL: ORA-00904: "INP"."COLUMN_VALUE": invalid identifier

  MERGE INTO tab_mapping tbl_llclm
       USING (
              SELECT COLUMN_VALUE as map_id
                FROM TABLE (p_llcl_map_array) inp)
          ON (inp.COLUMN_VALUE = tbl_llclm.lab_loinc_map_id)
  WHEN NOT MATCHED
  THEN
     INSERT     (tab_map_id,
                 tab_loinc_map_id,
                 last_updated_by,
                 last_updated_date)
         VALUES (p_llc_id,
                 inp.map_id,
                 p_last_updated_by,
                 SYSDATE);

p_llcl_map_array is of type num_arr (num_arr is SQL type TABLE of number)


Solution

  • This should work. I just moved the alias inp outside and referred the COLUMN_VALUE by map_id

    MERGE INTO tab_mapping tbl_llclm
           USING (
                  SELECT COLUMN_VALUE as map_id
                    FROM TABLE (p_llcl_map_array) 
                 ) inp
              ON (inp.map_id = tbl_llclm.lab_loinc_map_id)
      WHEN NOT MATCHED
      THEN
         INSERT     (tab_map_id,
                     tab_loinc_map_id,
                     last_updated_by,
                     last_updated_date)
             VALUES (p_llc_id,
                     inp.map_id,
                     p_last_updated_by,
                     SYSDATE);