Oracle to_date() 输出不正确

发布于 2024-12-13 19:30:32 字数 468 浏览 2 评论 0原文

一定有一个非常简单的答案,但我在任何地方都找不到它。

我有以下内容,这是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扶醉桌前 2024-12-20 19:30:32

假设 w.end_Dateq._renewal_date 是实际日期,您需要 to_char 它们,而不是 to_date。目前我想说的是,您看到的日期格式是由 NLS 设置指定的。 (如果它们不是日期,您将它们转换为日期,但仍然让您的 NLS 设置选择您查看它的格式)

Assuming w.end_Date and q._renewal_date are actual dates, you want to to_char them, not to_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)

南渊 2024-12-20 19:30:32

当您对值进行 TO_DATE 操作时,Oracle 在内部将其存储为日期。它会使用您的 NLS_DATE 设置值显示给您,我假设默认情况下将其设置为 DD-MON-YY

您可以检查

SELECT *
  FROM v$parameter
 WHERE name = 'nls_date_format';

您需要更改您的 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 to DD-MON-YY by default.

You can check with

SELECT *
  FROM v$parameter
 WHERE name = 'nls_date_format';

You'll need to either alter your NLS_DATE_FORMAT setting (either for your session or for the DB) or TO_CHAR the output to the format you want to see.

回忆追雨的时光 2024-12-20 19:30:32

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文