我有一张包含以下数据的表格:
ITEM LOCATION RECEIVE_DATE
001 13001 27-JAN-2016
002 14001 null
我使用以下内容以两个参数检索结果:
select * from item_master
where
(TRUNC (RECEIVE_DATE) between NVL(:STARTDATE, TRUNC(RECEIVE_DATE)) and NVL(:enddate, trunc(RECEIVE_DATE)));
如果我将两个日期参数都输入为空,我只获取RECEIVE_DATE的记录并排除所有记录为空RECEIVE_DATE
如果我没有为参数输入任何值,我应该如何检索所有行?
答案 0 :(得分:2)
您可以添加OR
和IS NULL
:
select *
from item_master
where
(TRUNC(RECEIVE_DATE)
between NVL(:STARTDATE, TRUNC(RECEIVE_DATE)) and NVL(:enddate, trunc(RECEIVE_DATE)))
OR (:STARTDATE IS NULL AND :enddate IS NULL);