我有一个"DATE“类型的列,我想对它运行一个查询,将它与sysdate进行比较。
但是我得到了以下错误,谁能让我知道我这里遗漏了什么?
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发布于 2012-02-05 15:05:41
你不应该在日期上使用to_date,To_date是用来将变量字符转换为日期的,而不是日期。
如果您在日期上使用函数to_date,那么oracle将根据nls_date_format将其引用为字符串,这在不同的环境中可能会有所不同。
正如@jonearles所说,如果你想删除sysdate中的时间,那么使用TRUNC
发布于 2012-02-05 15:38:15
使用:
select distinct file_name as r
from table_1
where view_day >= TRUNC(SYSDATE-10)发布于 2012-02-05 14:42:56
错误显示VIEW_DAY列是varchar,因此您需要将日期转换为字符串。使用TO_CHAR或将VIEW_DAY转换为date类型。
https://stackoverflow.com/questions/9147393
复制相似问题