【发布时间】:2017-04-26 06:38:58
【问题描述】:
我在我的机器上使用 Oracle XE。
将表定义为:
Name Type
ENAME VARCHAR2(20)
DOJ DATE
触发一个简单的选择:
从 test1.tasty1 中选择 *;
ENAME DOJ
sat 08-DEC-16
好吧 - 我知道 DATE 字段中包含时间组件。
以下使用 TRUNC 的查询工作正常:
select * from test1.tasty1 where trunc(DOJ) = '08-DEC-16';
现在我想测试 'to_date' 函数 - 但以下查询均无效 - 想知道为什么?
select * from test1.tasty1 where DOJ = to_date('08-12-2016','DD-MM-YYYY');
select * from test1.tasty1 where DOJ = to_date('08-DEC-2016','DD-MON-YYYY');
选择 * 从 test1.tasty1 where DOJ = to_date('08-DEC-16','DD-MON-YY');
选择 * 来自 test1.tasty1 where DOJ = to_date('08-DEC-16','dd-mon-RR');
在 SO 上看过以下内容:
Oracle TO_DATE not working
所以不确定这里有什么问题?
【问题讨论】:
-
请尝试以下查询:
SELECT * FROM test1.tasty1 WHERE DOJ = '2016-08-12'... 这会返回任何内容吗? AFAIK 您尝试的 4 个查询中的一些应该返回该记录。 -
如果我尝试 'select * from test1.tasty1 where DOJ = '08-DEC-16';',上述失败并显示 'literal does not match format string'没有结果
-
这不是我要求你运行的。我让你跑
WHERE DOJ = '2016-08-12' -
好吧,如果你读了我的回复-我确实回复说它失败了'字面不匹配格式字符串'
-
您确定
DOJ是date列吗?这是我在这里看到的非常奇怪的行为。