Multiple queries in merge into statement I have a scenario where i want to insert record if it doesn't exist in DB2. 
If it already exists update is_active column to 0 of the existing row and insert the new row with is_active as 1.

I cannot use merge into as i cannot run 2 queries in when matched section.

How can i achieve this in batch.

If i were to run queries one by one i could have run them. But since there are millions of such records i want to do this in batch.

I want to do this using java prepared statement.
Using temporary table

create table test_tab (id int not null, is_active int not null) in userspace1;

with stream (id) as (values 
--1, 2, 3
--2, 3, 4
3, 4, 5
)
, upd as (
select count(1) cnt
from new table(
  update test_tab t
  set is_active=0
  where is_active=1 and exists (select 1 from stream s where s.id=t.id)
)
)
select count(1) cnt
from new table(
  insert into test_tab(id, is_active)
  select id, 1
  from stream
);

select * from test_tab;


Assuming you accumulate your batch values into the streams table before each attempt to change the base table test_tab.
You can do all your operations using such a single statement as described above.
If you want to use some real table instead of streams, it's worth to collect statistics on it before every such a statement and test the performance using various number of records in the streams table.

Using batch inserts

create table test_tab2 (id int not null, is_active int not null default 1, id_int bigint not null generated always as identity) in userspace1;
create index test_tab2_idx on test_tab2(id);

create trigger test_tab2_air
after insert on test_tab2
referencing new as n
for each row
update test_tab2 t
set is_active=0
where t.is_active=1 and t.id=n.id and t.id_int&lt;&gt;n.id_int;

insert into test_tab2 (id) values 
--1, 2, 3
--2, 3, 4
3, 4, 5
;


You can just insert new records in batches in your java program. The trigger deactivates the corresponding old records.