检查情况oracle的情况

时间:2016-01-13 10:36:41

标签: oracle case where clause

这是我用来检查条件的查询。到目前为止,我没有得到解决方案。当我执行错误时,错误关键字。怎么做。

 select * from customer where status='A' and (case when trim(member_since) is not null then member_since > TO_DATE ( '20160112 235959' , 'YYYYMMDD HH24MISS')
 else registration_date <=TO_DATE ( '20160112 235959' , 'YYYYMMDD HH24MISS') end)

2 个答案:

答案 0 :(得分:1)

您可以使用一些布尔逻辑重写:

SELECT *
FROM customer
WHERE     status = 'A'
   AND ( TRIM(member_since) IS NOT NULL AND member_since > TO_DATE('20160112 235959', 'YYYYMMDD HH24MISS') OR
         TRIM(member_since) IS NULL AND registration_date <= TO_DATE('20160112 235959', 'YYYYMMDD HH24MISS')
       )

答案 1 :(得分:0)

select *
from customer
where status='A'
  and trim(member_since) is not null and  member_since > TO_DATE ('20160112 235959', 'YYYYMMDD HH24MISS') 

  union all

  select *
from customer
where status='A'
  and trim(member_since) is  null and    registration_date <=TO_DATE ('20160112 235959', 'YYYYMMDD HH24MISS')