I have a huge query and I am wondering if it is in Oracle possible to get the result of a case-when-statement and use it for comparison? My CASE-STATEMENT is declared in the Select-Statement and it looks like this.
SELECT........
(CASE
WHEN (Select 1 from DUAL) = 1 THEN 'TEST'
ELSE 'TEST2'
END) AS TEST;
Now I want to get the result of this case-statement and use it in the where part? Is it possible? (Sry this may be a dumb question)
TESTin theSELECTclause, the nameTESTis not visible in theWHEREclause of the sameSELECTquery, becauseWHEREis processed beforeSELECT. If you don't want to repeat the same (possibly very long)CASEexpression in theWHEREclause, you are better off definingTESTin a subquery, then select and use it in theWHEREclause in an outer query. (You can do that with aWITHclause.) Better for future code maintenance, too.