简体   繁体   English

oracle LAST_DAY(sysdate)比较问题

[英]oracle LAST_DAY(sysdate) comparison problem

Suppose i have a Date column which has the date 31-JUL-2011.假设我有一个日期列,其日期为 31-JUL-2011。 Im getting the last date of the month using LAST_DAY(sysdate) which returns 31-JUL-11.我使用返回 31-JUL-11 的 LAST_DAY(sysdate) 获取该月的最后一个日期。 But When i do a simple = comparison it does not give the result..i mean suppose tablename.lastdateofmonth = LAST_DAY(sysdate) it does not give the result but if i use tablename.lastdateofmonth = to_date('2011/07/31', 'yyyy/mm/dd') it gives the result.但是当我做一个简单的 = 比较时,它没有给出结果..我的意思是假设 tablename.lastdateofmonth = LAST_DAY(sysdate) 它没有给出结果,但是如果我使用 tablename.lastdateofmonth = to_date('2011/07/31' , 'yyyy/mm/dd') 它给出了结果。

Thanks.谢谢。

last day makes the current date as the last day of the month. last day 使当前日期成为该月的最后一天。 however it keeps the time.但是它保持时间。 you must trunc the values if you are going to compare them by just day-month-year.如果要按天-月-年比较它们,则必须截断这些值。 Truncing them will solve your problem.截断它们将解决您的问题。

tablename.lastdateofmonth = trunc(LAST_DAY(sysdate))

LAST_DAY(sysdate) will return you the last date of the month including the time part. LAST_DAY(sysdate) 将返回该月的最后一个日期,包括时间部分。

Looks like the data in the column lastdateofmonth is just having date part and the imte part defaulted to 12:00 AM.看起来 lastdateofmonth 列中的数据只有日期部分,而 imte 部分默认为 12:00 AM。

Try using this:尝试使用这个:

tablename.lastdateofmonth = TRUNC(LAST_DAY(sysdate))

last_day() preserves the time component of sysdate. last_day() 保留 sysdate 的时间部分。 Use it together with trunc() like this:将它与 trunc() 一起使用,如下所示:

select *
from table_name
where lastdateofmonth = last_day(trunc(sysdate));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM