2

Sorry I am new in PL/SQL toad for oracle. I have a simple problem. I need to find some column name in this table "JTF_RS_DEFRESOURCES_VL" and i do that with this script. just an example column.

SELECT column1, 
       column2, 
       column3, 
       column4, 
       column5, 
       end_date_active 
FROM   jtf_rs_defresources_vl 

Then i want to use "if else statement" that if END_DATE_ACTIVE = null then it is active else it is inactive.

Never Stop Learning
  • 755
  • 1
  • 10
  • 34

3 Answers3

2

It sounds like you want a CASE statement

SELECT (CASE WHEN end_date_active IS NULL 
             THEN 'Active'
             ELSE 'Inactive'
         END) status,
       <<other columns>>
  FROM jtf_rs_defresources_vl
Justin Cave
  • 227,342
  • 24
  • 367
  • 384
1

You can use a CASE expression like @Justin suggested, but in Oracle there's a simpler function - NVL2. It receives three arguments and evaluates the first. If it isn't null the second argument is returned, if it is, the third one is returned.

So in your case:

SELECT NVL2(end_date_active, 'Active', 'Inactive') AS status,
       <<other columns>>
  FROM jtf_rs_defresources_vl
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0
select case end_date_active 

   when is null then 'ACTIVE',

   else 'INACTIVE'

   end as 'STATUS'

from jtf_rs_defresources_vl ;

redsoxlost
  • 1,215
  • 5
  • 19
  • 32