Comparing date with sysdate in oracle

ぃ、小莉子 提交于 2019-11-28 07:41:50

问题


I have a column which is of "DATE" type and I want to run a query on it comparing it with sysdate.

But I am getting following error, Can someone please let me know what I am missing here?

SQL> select distinct file_name as r 
     from table_1 
     where view_day >= TO_DATE(SYSDATE-10, 'YYYY/MM/DD');

ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected

回答1:


You shouldn't use to_date on a date, To_date is for casting a varchar to date, not a date.
If you do use the function to_date on a date, then oracle will refer to it as a string according to nls_date_format which may vary in different environments.
As @jonearles said, if you want to remove the time in sysdate then use TRUNC




回答2:


USE:

select distinct file_name as r 
from table_1 
where view_day >= TRUNC(SYSDATE-10)



回答3:


Error shows that a VIEW_DAY column is varchar so you need to convert DATE to String. Use TO_CHAR or convert VIEW_DAY to date type.



来源:https://stackoverflow.com/questions/9147393/comparing-date-with-sysdate-in-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!