简体   繁体   English

选择语句和If / else语句

[英]Select statement And If/else statement

Sorry I am new in PL/SQL toad for oracle. 对不起,我是oracle的PL / SQL toad新手。 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. 我需要在这个表“JTF_RS_DEFRESOURCES_VL”中找到一些列名,我用这个脚本来做。 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. 然后我想使用“if else语句”,如果END_DATE_ACTIVE = null则它处于活动状态,否则它处于非活动状态。

It sounds like you want a CASE statement 听起来你想要一个CASE声明

SELECT (CASE WHEN end_date_active IS NULL 
             THEN 'Active'
             ELSE 'Inactive'
         END) status,
       <<other columns>>
  FROM jtf_rs_defresources_vl

You can use a CASE expression like @Justin suggested, but in Oracle there's a simpler function - NVL2 . 您可以使用像@Justin建议的CASE表达式,但在Oracle中有一个更简单的函数 - 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. 如果它不为 null ,则返回第二个参数,如果是,则返回第三个参数。

So in your case: 所以在你的情况下:

SELECT NVL2(end_date_active, 'Active', 'Inactive') AS status,
       <<other columns>>
  FROM jtf_rs_defresources_vl
select case end_date_active 

   when is null then 'ACTIVE',

   else 'INACTIVE'

   end as 'STATUS'

from jtf_rs_defresources_vl ; 来自jtf_rs_defresources_vl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM