Search notes:

Oracle SQL: MERGE values into a flag-table

create table tq84_flags (
   id      integer primary key,
   flg_01  varchar2(1) default 'N' not null check (flg_01 in ('N', 'Y')),
   flg_02  varchar2(1) default 'N' not null check (flg_02 in ('N', 'Y')),
   flg_03  varchar2(1) default 'N' not null check (flg_03 in ('N', 'Y'))
);

begin

   merge into tq84_flags      flg
   using ku$_vcnt(1, 3, 4, 6) src on ( flg.id = src.column_value )
   when     matched then update set flg_01 = 'Y'
   when not matched then insert (id, flg_01) values (src.column_value, 'Y');

   merge into tq84_flags      flg
   using ku$_vcnt(2, 3, 4, 5) src on ( flg.id = src.column_value )
   when     matched then update set flg_02 = 'Y'
   when not matched then insert (id, flg_02) values (src.column_value, 'Y');

   merge into tq84_flags      flg
   using ku$_vcnt(1, 2, 3   ) src on ( flg.id = src.column_value )
   when     matched then update set flg_03 = 'Y'
   when not matched then insert (id, flg_03) values (src.column_value, 'Y');

   commit;
end;
/

select * from tq84_flags order by id;
--
--         ID F F F
-- ---------- - - -
--          1 Y N Y
--          2 N Y Y
--          3 Y Y Y
--          4 Y Y N
--          5 N Y N
--          6 Y N N

See also

The merge statement

Index