当单行中的语句获取Oracle SQL时遇到的情况问题

时间:2018-10-10 15:26:55

标签: sql oracle plsql

我只有一行数据,如下所示:

dyn1 dyn2 dyn3 chg
   1    0    1 768

现在我想写一个

这样的条件条件
Case when dyn1 = 1 then 7 When dyn2=1 then 7 When dyn3=1 then 7 End

现在,以上记录表明它没有检查dyn3值,因为它将dyn1值设为true。

如何处理此代码?

1 个答案:

答案 0 :(得分:0)

我假设您需要在select语句中返回这些值,也许对您有帮助。

SELECT  CASE WHEN dyn1 = 1 THEN 7 END,
        CASE WHEN dyn2 = 1 THEN 7 END,
        CASE WHEN dyn3 = 1 THEN 7 END
FROM (SELECT 1 AS dyn1, 1 AS dyn2, 1 AS dyn3 FROM dual);

或者,也许您只希望在其列中输入

SELECT  CASE WHEN dyn1 = 1 THEN 7 END ||
        CASE WHEN dyn2 = 1 THEN 7 END ||
        CASE WHEN dyn3 = 1 THEN 7 END
from (select 1 as dyn1, 1 as dyn2, 1 as dyn3 from dual);