考虑一个类似的 sql 查询
SELECT a, b>now() as expired 
FROM TABLE;
其中 b 是日期并检查当前日期。
我发现now()应该替换为SYSDATE
但是怎么写
 b > (SYSDATE) as expired 
甲骨文?
Oracle 没有布尔数据类型(MySQL 也没有,但它只是将任何不等于零的数字视为“真”),因此您需要返回一个表示过期的数字0和1
select a, 
       case 
          when b > sysdate then 1
          else 0
       end as expired
from the_table;
请注意,Oracle 的DATE数据类型包括时间。所以SYSDATE返回类似2013-04-04 14:43:12. 您可能想在比较中使用 trunc() :
select a, 
       case 
          when trunc(b) > trunc(sysdate) then 1
          else 0
       end as expired
from the_table;
当然,您可以在 case 语句中返回任何内容,而不仅仅是数字
select a, 
       case 
          when trunc(b) > trunc(sysdate) then 'expired'
          else 'active'
       end as expired
from the_table;