【发布时间】:2014-04-21 18:57:23
【问题描述】:
问题已解决 - 请参阅本文结尾。
当我在 select 子句中调用 to_date 时,一切正常 - 获得 12 条记录的结果集:
select value1,to_date(value1,'DD.MM.YYYY')
from variableindex
where
value1 is not null
and value1 <> '0'
and creation_time_ > to_timestamp('20140307','YYYYMMDD')
order by 2
返回
'VALUE1' 'TO_DATE(VALUE1,'DD.MM.YYYY')'
'25.11.2013' 25.11.13
'12.03.2014' 12.03.14
'12.03.2014' 12.03.14
'12.03.2014' 12.03.14
'12.03.2014' 12.03.14
'12.03.2014' 12.03.14
'14.03.2014' 14.03.14
'14.03.2014' 14.03.14
'14.03.2014' 14.03.14
'14.03.2014' 14.03.14
'20.03.2014' 20.03.14
'20.03.2014' 20.03.14
每个日期字符串都已按预期转换。
如果我将以下行添加到 where 子句
and to_date(value1,'DD.MM.YYYY') < to_date('20140301','YYYYMMDD')
我会收到:
ORA-01847: Tag des Monats muss zwischen 1 und letztem Tag des Monats liegen
01847. 00000 - "day of month must be between 1 and last day of month"
*Cause:
*Action:
不,它真的很讨厌...我将查询更改为
where id_ in (...)
并使用与原始查询相同的 12 个记录集 ID。没有错误...
非常感谢@GordonLinoff - 这就是我现在使用查询的方式:
select value1,to_date(value1,'DD.MM.YYYY') from variableindex
where
(case when value1 <> '0' then to_date(value1,'DD.MM.YYYY') end) > to_timestamp('20131114','YYYYMMDD')
and creation_time_ > to_timestamp('20140307','YYYYMMDD')
order by 2;
【问题讨论】:
-
尝试 select to_date('20140301','YYYYMMDD') from dual 并检查输出
-
我想知道为什么它应该在 select 子句中起作用,而不是在 where 子句中
-
@Joggl 。 . .这真的是表中的所有数据吗?
-
@GordonLinoff 没有,但它是使用“and creation_time_ > to_timestamp('20140307','YYYYMMDD')”时的所有内容
-
这是因为过滤器
value1 <> '0'可能会在您转换to_date(value1,'DD.MM.YYYY')之后应用。可能,这是 Oracle 的“功能”,看起来像一个错误。