Oracle SQL merge statement with only 1 table and many values

I am using Spring JDBC and Oracle SQL.

using the SpringJDBC class MapSqlParameterSource, I matched the data I want to combine.

Now I want to use the merge operator to update / insert the database table. I have one table and many parameters that I want to combine into it.

 merge into proj.person_registry pr
using ( ! parameters should go here somehow? )
on (pr.id = :id or pr.code = :code)
when matched then 
update set pr.code             = :code,
        pr.name                 = :name,
        pr.firstname            = :firstname,
        pr.cl_gender            = :cl_gender,
        pr.cl_status            = :cl_status,
        pr.aadress              = :aadress,
        pr.aadress_date         = :aadress_date 
when not matched then
insert values (:code, :name, :firstname, :cl_gender, :cl_status, ;aadress, :aadress_date);

Should I somehow create a temporary table for the keyword using or is there another way? how would i go for a merger like that?

pr.id pr.code. : id null, , , pr.code, : code. , :

update set pr.code             = :code,
+5
1

:

merge into proj.person_registry pr
using ( 
  select 42 as id
         'xyz' as code,
         'Dent' as name,
         'Arthur' as firstname,
         'male' as cl_gender
         'closed' as cl_status,
         'Somewher' as aaddress,
         current_date as aaddress_date
   from dual
) t on (pr.id = t.id or pr.code = t.code)
when matched then 
update set pr.code             = t.code,
        pr.name                 = t.name,
        pr.firstname            = t.firstname,
        pr.cl_gender            = t.cl_gender,
        pr.cl_status            = t.cl_status,
        pr.aadress              = t.aadress,
        pr.aadress_date         = t.aadress_date 
when not matched then
insert values (t.code, t.name, t.firstname, t.cl_gender, t.cl_status, ;aadress, t.aadress_date);

JDBC Spring, select ... from dual - .

+5

All Articles