I want to return the primary key from an oracle merge query. I'm using a single statement to insert if not exist and I don't want to use procedure or function to do so..
this is the sample query
merge into myTable e
using (select :empname name from dual) s
on (UPPER(TRIM(e.empname)) = UPPER(TRIM(s.name)))
when not matched then insert (empname)
values (s.name)
and I need to get another primary key field of the myTable. the primary key is inserted using sequence and trigger
I tried adding RETURNING empID into :empId
but it gives error
There's a problem.
Merge Into
doesn't support Returning Into
, so that won't work.To solve it:
sql%rowcount
return 0 after the update, perform the insert instead.UPPER(TRIM(name))
) to find the record that was updated.