【发布时间】:2019-06-07 07:38:32
【问题描述】:
假设有这样的表结构
Name | Class | CS_ex_date | IT_ex_date|
xyz | CSE | 10 june | Null |
123 | ECE | Null | Null |
456 | MECH | Null | Null |
678 | MECH | Null | Null |
abc | IT | Null | 3 Aug |
我想使用 case 语句创建一个 select 语句,case 语句中有一些条件。
我已经在 where 条件中看到了 case 语句和 case 语句的常用语法,但我想在 THEN 部分中添加一些条件。我的语法有问题,找不到任何可以参考的例子。
我的查询是这样的:
select *
from student
where (case
when class like '%SE%'
then CS_ex_date > sysdate and CS_ex_date < sysdate + 60
when class like '%T%'
then IT_ex_date > sysdate and IT_ex_date < sysdate + 60
end);
我不确定查询的语法并得到 ORA-00905: missing keyword。
预期的输出应该是
Name | Class | CS_ex_date | IT_ex_date|
xyz | CSE | 10 june | Null |
abc | IT | Null | 3 Aug |
有没有办法解决这个问题。使用任何其他方法都会产生相同的结果。
【问题讨论】:
-
它实际上是一个case 表达式。这不是一个微不足道的区别:一个表达式返回一个单一的原子值。这意味着它不能以这种方式用于程序流。