Oracle to_date() 输出不正确
一定有一个非常简单的答案,但我在任何地方都找不到它。
我有以下内容,这是我的 select
语句的一部分:
case when q.renewal_date is not null then
to_date(q._renewal_date, 'DD/MM/YYYY')
else
to_date(w.END_DATE, 'DD/MM/YYYY')
end END_DATE,
根据我能找到的所有文档,MM
应该以数字形式给出月份,但是我得到了结果例如:
30-SEP-12
26-JUN-11
30-SEP-12
同样有趣的是它们是连字符 (-) 而不是斜线 (/)。
那么这是什么原因以及我如何实现我想要的呢?
There must be a very simple answer, but I can't find it anywhere.
I have the following which is a section of my select
statement:
case when q.renewal_date is not null then
to_date(q._renewal_date, 'DD/MM/YYYY')
else
to_date(w.END_DATE, 'DD/MM/YYYY')
end END_DATE,
according to all of the docs I can find the MM
should give the month in numbers however I'm getting results such as:
30-SEP-12
26-JUN-11
30-SEP-12
It's also interesting that they're hyphenated (-) and not with slashes (/).
So what's the reason for this and how do I achieve what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设
w.end_Date
和q._renewal_date
是实际日期,您需要to_char
它们,而不是to_date
。目前我想说的是,您看到的日期格式是由 NLS 设置指定的。 (如果它们不是日期,您将它们转换为日期,但仍然让您的 NLS 设置选择您查看它的格式)Assuming
w.end_Date
andq._renewal_date
are actual dates, you want toto_char
them, notto_date
. At present I would say you are seeing the dates in the format specified by your NLS settings. (If they are not dates, you are converting them to dates, but still letting your NLS settings choose the format you view it in)当您对值进行 TO_DATE 操作时,Oracle 在内部将其存储为日期。它会使用您的
NLS_DATE
设置值显示给您,我假设默认情况下将其设置为DD-MON-YY
。您可以检查
您需要更改您的
NLS_DATE_FORMAT
设置(对于您的会话或数据库)或TO_CHAR
将输出更改为您想要查看的格式。As you are TO_DATEing the value it is stored by Oracle internally as a date. It is displayed back to you using your
NLS_DATE
settings value which i would assume are set toDD-MON-YY
by default.You can check with
You'll need to either alter your
NLS_DATE_FORMAT
setting (either for your session or for the DB) orTO_CHAR
the output to the format you want to see.to_date 将字符串转换为日期。您拥有的代码采用“DD/MM/YYYY”格式的字符串(q._renewal_date)并将其转换为日期。您看到的是日期字段的默认呈现。
根据 q._renewal_date 的类型,您可能需要使用不同的转换/格式化函数。
to_date converts a string to a date. The code you have is taking a string (q._renewal_date) in 'DD/MM/YYYY' format and converting it to a date. What you are seeing is the default rendering of the date field.
Depending on what type q._renewal_date is, you probably need to use a different conversion/formatting function.