I am new to oracle sql and trying to extract the value from table. I want to extract certain column and a new value which should be the output of if else
Condition I am trying:
select name, variable 1 (this value should be the value returning from if else condition) from table1
what I tried till now
BEGIN
IF columnA== 'xxx' OR PM == 1 THEN
columnA:= 'xxx';
ELSIF columnA== 'yyy' AND PM == 0 THEN
columnA:= 'yyy';
END IF;
END;
So the variable1 should be 'columnA' value which is returned from if else
How can I do this? if not guide me to right path
CodePudding user response:
Porting your current if else logic to a CASE
expression, we can try:
SELECT name,
CASE WHEN columnA = 'xxx' OR PM = 1 THEN 'xxx'
WHEN columnA = 'yyy' AND PM = 0 THEN 'yyy' END AS variable1
FROM yourTable;