n_ttyp object was used to easily provide the required input data.
The question didn't state what happens if there are multiple values that do not exist, e.g. 3, 7, 9, does the output generate multiple occurrences of ID values or distinct?
create type n_ttyp as table of number
/
create table m
(id number,
ntyp number)
/
insert into m values(1, 0);
insert into m values(2, 0);
insert into m values(3, 1);
insert into m values(4, 2);
commit;
with q as (
select *
from table(n_ttyp(2,3)))
select m2.id,
m.*,
q.*
from m m2,
m,
q
where m.ntyp (+)= q.column_value
and m2.ntyp = nvl(m.ntyp, 0)
/
ID ID NTYP COLUMN_VALUE
---------- ---------- ---------- ------------
1 3
2 3
4 4 2 2
with q as (
select *
from table(n_ttyp(1,2)))
select m2.id, m.*, q.*
from m m2,
m,
q
where m.ntyp (+)= q.column_value
and m2.ntyp = nvl(m.ntyp, 0)
/
ID ID NTYP COLUMN_VALUE
---------- ---------- ---------- ------------
3 3 1 1
4 4 2 2
with q as (
select *
from table(n_ttyp(1)))
select m2.id, m.*, q.*
from m m2,
m,
q
where m.ntyp (+)= q.column_value
and m2.ntyp = nvl(m.ntyp, 0)
/
ID ID NTYP COLUMN_VALUE
---------- ---------- ---------- ------------
3 3 1 1