NoName123
NoName123

Reputation: 137

ORACLE: SELECT VALUE IF

I am trying to select different values that depend on different conditions, but I don't exactly know, how one can achieve this in SQL/Oracle..

Here is an example:

SELECT VALUE (I dont exactly know what to write here)
FROM
  (SELECT 
  (CASE
     WHEN (Select 1 from DUAL) = 1 THEN 'TEST'
     WHEN (Select 1 from DUAL) = 0 THEN 'TEST1'
     WHEN (Select 1 from DUAL) = 0 THEN 'TEST2'
     ELSE 'N/A'
  END) 
FROM DUAL);

I want to print different results according to the conditions...For instance, in the example above it should print "TEST"

Upvotes: 0

Views: 77

Answers (1)

MT0
MT0

Reputation: 167972

You need to provide an alias to the CASE statement:

SELECT alias_for_your_case_value
FROM   (
  SELECT CASE (Select 1 from DUAL)
           WHEN 1 THEN 'TEST'
           WHEN 0 THEN 'TEST1'
           WHEN 0 THEN 'TEST2'
           ELSE 'N/A'
         END AS alias_for_your_case_value
  FROM   DUAL
);

Upvotes: 1

Related Questions