Oracle SQL:以日期格式的表演月份
我想显示一个使用以下内容创建的计算列:
to_char(
COALESCE(
date1,
date2,
date3
),
'MONTH - YYYY'
) month_year_column
但是问题是返回字符串需要一个日期字段
I would like to show a calculated column that is created using the following:
to_char(
COALESCE(
date1,
date2,
date3
),
'MONTH - YYYY'
) month_year_column
but the problem is this returns a string need a date field instead
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在Oracle中,
日期
是一种二进制数据类型,由7个字节组成:代表:世纪,世纪,月,日,小时,小时,分钟和秒。 总是具有所有这些组件,并且从未以任何特定(人类可读)格式存储。因此,不可能拥有
date
数据类型和特定格式。如果要
date
值,而将日和时间组件设置为一个月的第一天的午夜,则可以使用:注意:然后,这将由客户端应用程序格式化您用于根据其默认日期格式规则访问数据库(可能不会显示日期的所有组件);这不会改变数据库将值存储为7字节二进制值,无论客户端应用程序如何选择显示它。
如果您想要使用特定格式的格式,则不能使用(未格式化)
date
,需要将值转换为可以格式化的另一种数据类型,例如字符串,您可以使用代码:In Oracle, a
DATE
is a binary data type that consists of 7 bytes representing: century, year-of-century, month, day, hours, minutes and seconds. It ALWAYS has all of those components and is NEVER stored with any particular (human-readable) format.Therefore, it is impossible to have a
DATE
data type and a particular formatting.If you want a
DATE
value where the day and time components are set to midnight of the first day of the month then you can use:Note: this will then be formatted by the client application you are using to access the database according to its default date formatting rules (which may not show all the components of the date); this does not change that the database will store the value as a 7-byte binary value regardless of how the client application choses to display it.
If you do want it with a particular formatting then you cannot use a (unformatted)
DATE
and need to convert the value to another data type that can be formatted, such as a string and you can use your code:我想您可以使用NVL而不是Colesce来避免丢失日期数据类型。
I guess you can use NVL instead of COALESCE to avoid losing the DATE data type.