SQL Oracle/Toad 期望什么日期格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10216269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What date format does Oracle/Toad expect?
提问by B. Clay Shannon
In the Toad editor, I've got this SQL:
在 Toad 编辑器中,我有这个 SQL:
SELECT INTERLOPERABCID,AVAILABLEDATE,
AVAILABLEQHR,CARPHONEID,
TRUNC((AVAILABLEQHR-1)/12) "COL",
MOD(AVAILABLEQHR-1,12) "ROW"
FROM ABC.INTERLOPERAVAILABILITY
WHERE INTERLOPERABCID>42
AND AVAILABLEDATE='09/Apr/2012'
...but it returns no rows, even though I see many records in the table whose AVAILABLEDATE value = '4/9/2012'
...但它不返回任何行,即使我在表中看到许多记录的 AVAILABLEDATE 值 = '4/9/2012'
The date format ('09/Apr/2012'; I also tried '04/Sep/2012') looks odd, but at least I get no compilation/execution error with it. When I tried "4/9/2012" and "04/09/2012" it said "ORA-01853: not a valid month"
日期格式('09/Apr/2012';我也试过'04/Sep/2012')看起来很奇怪,但至少我没有遇到编译/执行错误。当我尝试“4/9/2012”和“04/09/2012”时,它说“ORA-01853:无效月份”
How must I enter the date to tell it I want to see dates of April 9th, 2012?
我必须如何输入日期才能告诉它我想查看 2012 年 4 月 9 日的日期?
回答by cagcowboy
Safest to use TO_DATE:
最安全的使用 TO_DATE:
AND AVAILABLEDATE = TO_DATE('09/Apr/2012', 'DD/Mon/YYYY')
回答by Cade Roux
I like to use the date literal:
我喜欢使用日期文字:
SELECT INTERLOPERABCID,AVAILABLEDATE,
AVAILABLEQHR,CARPHONEID,
TRUNC((AVAILABLEQHR-1)/12) "COL",
MOD(AVAILABLEQHR-1,12) "ROW"
FROM ABC.INTERLOPERAVAILABILITY
WHERE INTERLOPERABCID>42
AND AVAILABLEDATE = DATE '2012-04-09'
Are you sure there is no time part in your dates?
您确定您的日期中没有时间部分吗?