if else statement in oracle with condition
SELECT (CASE
WHEN b.status IN ('AC', 'AB')
THEN a.coulmn_id = c.coulmn_id
WHEN b.status IN ('GC')
THEN a.coulmn_id = 241
END
) status
FROM table_1 a,
table_2 b,
table_3 c
What you posted doesn't make sense; as if that CASE
was supposed to be in the WHERE
clause, eg
select ...
from table_1 a, table_2 b, table_3 c
where a.column_id = case when b.status in ('AC', 'AB') then c.column_id
when b.status in ('GC') then 241
end
I think you are looking for the values which satisfy the dynamic condition.
You can use boolean operation instead of CASE..WHEN
as follows:
FROM
...
WHERE where ((a.column_id != 241 and a.column_id = c.column_id
and b.status in ('AC', 'AB'))
OR (a.column_id = 241 and b.status in ('GC') ))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.