Oracle 中的日期月份名称语言?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6069785/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:44:07  来源:igfitidea点击:

Dates month names language in Oracle?

stringoracledatetime

提问by filippo

I have a varcharfield 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_dateconfiguring 'Mon DD YYYY HH:MIAM'.

我的varchar表中有一个包含日期的字段,格式为: Dic 31 1999 12:00AM,通常可以使用to_date配置'Mon DD YYYY HH:MIAM'.

Month names can of course come in any language. For instance, January, would be Janin English and Enein Spanish.

月份名称当然可以使用任何语言。例如,一月将使用Jan英语和Ene西班牙语。

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.

我认为 Oracle 客户端会选择机器的语言环境来确定传入字符串的语言。唯一的问题是,如果您是一个无法真正知道日期来自何处的服务器,这将不会总是有效。

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?

我有什么方法可以告诉 Oracle,在执行时,我发送的是哪种语言?

The current ugly workaround is to translate not matching months to Spanish.

当前丑陋的解决方法是将不匹配的月份翻译成西班牙语。

回答by arnep

You can use SELECT * FROM NLS_SESSION_PARAMETERSto determine you current language settings (also NLS_INSTANCE_PARAMETERSand NLS_DATABASE_PARAMETERSexist).

您可以使用SELECT * FROM NLS_SESSION_PARAMETERS,以确定您当前语言设置(也NLS_INSTANCE_PARAMETERSNLS_DATABASE_PARAMETERS存在)。

Use NLS_*environment variables on your workstation or ALTER SESSIONstatements within your SQL session to change these language settings.

使用NLS_*工作站上的环境变量或ALTER SESSIONSQL 会话中的语句来更改这些语言设置。

回答by cem

You should use NLS_DATE_LANGUAGE for that:

您应该为此使用 NLS_DATE_LANGUAGE:

select to_char(sysdate, 'dd Month, Day', 'NLS_DATE_LANGUAGE = turkish') from dual

回答by Kajetan Abt

ALTER SESSION might work. I don't remember exactly how, but I know you can set locales, date styles and number formats with it.

ALTER SESSION 可能会起作用。我不记得具体是怎么做的,但我知道你可以用它设置语言环境、日期样式和数字格式。