This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / 怎样在SQL(ORACLE)中判断一个日期是否在一个日期范围内?比如, 要判断 A 是否在"04/01/2008" 到 "05/15/2008"? 谢谢!
-allhelp(allhelp);
2008-6-4
(#4483073@0)
-
dataStringParameter < to_char( colName, 'yyyy-mm-dd') and date .... something like that
-maplew2008(call me at 9.1.1);
2008-6-4
(#4483084@0)
-
好久没用oracle了,记不太清了。难道oracle里面不能直接用WHERE A BETWEEN DATE1 AND DATE2 么?
-bdbs(不多不少);
2008-6-5
(#4485585@0)
-
可以
-zhi007(zhi007);
2008-6-12
(#4498263@0)
-
如果 A 是带有时间的,DATE2 里的时间必须设到 23:59:59
-newkid(newkid);
2008-6-12
(#4498323@0)
-
如果DATE2要inclusive,我宁愿用DateAdd('dd',1,DATE2),不然你把23:59:59的数据exclude出去了。
-bdbs(不多不少);
2008-6-13
(#4499621@0)
-
between 是两端inclusive的(相当于>= AND <=)) date类型只精确到秒。所以如果DATE2设到23:59:59, 用between数据也不会漏掉。当然你可以用 A>=TRUNC(Date1) AND A<TRUNC(Date2)+1也是一样的
-newkid(newkid);
2008-6-13
(#4499676@0)
-
Oracle记录毫秒么?如果是的话,23:59:59.001 ~ 23:59:59.999 这一段是否会丢失?
-bdbs(不多不少);
2008-6-13
(#4499704@0)
-
date类型只精确到秒的,因此不会丢失。timestamp 可以精确到毫秒
-newkid(newkid);
2008-6-13
(#4499900@0)
-
哦。那这个跟SQL Server不一样。里面的script在SQL Server下结果是0。DECLARE @a datetime
SET @a = '2008-06-12 23:59:59.123'
SELECT CASE WHEN @a between '2008-06-12' and '2008-06-12 23:59:59' THEN 1
WHEN @a between '2008-06-12' and '2008-06-12 23:59:59.999' THEN 0
END
-bdbs(不多不少);
2008-6-13
{216}
(#4500112@0)
-
select 1 from dual where in_date_str between '20080401' and '20080501'
-copperbean(豆泡松果 之 铜豌豆);
2008-6-12
(#4498288@0)