将日期与 oracle 中的 sysdate 进行比较 [英] Comparing date with sysdate in oracle

查看:99
本文介绍了将日期与 oracle 中的 sysdate 进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DATE"类型的列,我想对它运行一个查询,将它与 sysdate 进行比较.

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

推荐答案

您不应该在日期上使用 to_date,To_date 用于将 varchar 转换为日期,而不是日期.
如果您确实在日期上使用了 to_date 函数,那么 oracle 会根据 nls_date_format 将其称为字符串,这在不同环境中可能会有所不同.
正如@jonearles 所说,如果您想删除 sysdate 中的时间,请使用 TRUNC

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

这篇关于将日期与 oracle 中的 sysdate 进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆