Oracle PL / SQL,当日期参数为Null时如何获取所有行?

问题描述 投票:0回答:1

这是我的查询语句:

   WHERE     date_column LIKE
                (CASE
                    WHEN :date_parameter IS NOT NULL
                    THEN
                        :date_parameter
                    ELSE '%%'  
                 END)
                 ...

如果参数为null,我想获取所有行。我该怎么办?

oracle plsql oracle10g
1个回答
-1
投票

尝试

WHERE (:date_parameter is null
       OR date_column = :date_parameter)

我曾经写过

WHERE date_column = nvl(:date_parameter,date_column)

但是我认为人们觉得它难以阅读。

© www.soinside.com 2019 - 2024. All rights reserved.