Oracle 中的日期月份名称语言?
我的表中有一个 varchar
字段,其中包含日期,格式为:Dic 31 1999 12:00AM
,通常可以使用 进行转换,不会出现任何问题to_date
配置'Mon DD YYYY HH:MIAM'
。
月份名称当然可以采用任何语言。例如,January 在英语中为 Jan
,在西班牙语中为 Ene
。
我认为 Oracle 客户端将选择计算机的区域设置来确定传入字符串的语言。唯一的问题是,如果您是一个无法真正知道日期来自何处的服务器,那么这并不总是有效。
我当前的问题是,每次我在西班牙语设置的计算机中尝试处理具有英文名称的月份的日期时,我都会收到“无效月份”错误。
有什么办法可以告诉 Oracle,关于执行时间,我发送的语言是什么?
当前丑陋的解决方法是将不匹配的月份翻译成西班牙语。
I have a varchar
field in my table which contains a date, formatted as: Dic 31 1999 12:00AM
, which can generally be converted without any problems using a to_date
configuring 'Mon DD YYYY HH:MIAM'
.
Month names can of course come in any language. For instance, January, would be Jan
in English and Ene
in Spanish.
I reckon the Oracle client will pick up the machine's locale to figure which is the language of the incoming string. The only problem is that this will not always work if you are a server where you can't really know where the date is coming from.
My current problem is that every time I'm in a Spanish set computer and try to process a date with English named months, I'll get an "invalid month" error.
Is there I way I could tell Oracle, on execution time, which is the language I'm sending?
The current ugly workaround is to translate not matching months to Spanish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用 NLS_DATE_LANGUAGE 为此:
You should use NLS_DATE_LANGUAGE for that:
您可以使用
SELECT * FROM NLS_SESSION_PARAMETERS
来确定当前的语言设置(还存在NLS_INSTANCE_PARAMETERS
和NLS_DATABASE_PARAMETERS
)。在工作站上使用
NLS_*
环境变量或 SQL 会话中的 ALTER SESSION 语句来更改这些语言设置。You can use
SELECT * FROM NLS_SESSION_PARAMETERS
to determine you current language settings (alsoNLS_INSTANCE_PARAMETERS
andNLS_DATABASE_PARAMETERS
exist).Use
NLS_*
environment variables on your workstation orALTER SESSION
statements within your SQL session to change these language settings.ALTER SESSION 可能会起作用。我不记得具体是怎么做的,但我知道你可以用它设置区域设置、日期样式和数字格式。
ALTER SESSION might work. I don't remember exactly how, but I know you can set locales, date styles and number formats with it.