在 Oracle 连接上设置区域设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5292721/
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
set locale on Oracle connection
提问by Dan Z.
In my company's product, we retrieve results a page at a time from the database. Because of this all filtering and sorting must be done on the database. One of the problems is coded values. For filtering and sorting to work properly, the code values need to be translated to locale specific labels in the query.
在我公司的产品中,我们一次从数据库中检索一个页面的结果。因此,所有过滤和排序都必须在数据库上完成。问题之一是编码值。为了使过滤和排序正常工作,需要将代码值转换为查询中的特定于区域设置的标签。
My plan is to use a table similar to the following: t_code_to_label ( type varchar2(10), locale varchar2(10), code varchar2(10), label varchar2(50) ) The first three columns are the primary (unique) key.
我的计划是使用类似于以下内容的表: t_code_to_label ( type varchar2(10), locale varchar2(10), code varchar2(10), label varchar2(50) ) 前三列是主(唯一)键。
When using this table, you would see something like this
使用此表时,您会看到类似这样的内容
select ent.name, ent.ent_type, entlabel.label as ent_type_label
from t_entitlements ent
join t_code_to_label entlabel on entlabel.type='entlabel' and entlabel.locale=currentLocale() and entlabel.code=ent.ent_type
select ent.name, ent.ent_type, entlabel.label as ent_type_label
from t_entitlements ent
join t_code_to_label entlabel on entlabel.type='entlabel' and entlabel.locale=currentLocale() and entlabel.code=ent.ent_type
The problem is that currentLocale() is something that I made up. How can I on the Java side of a JDBC connection do something to set the locale for the Connection object that I have that I can read on the Oracle side in a simple function. Ideally this is true locale support by Oracle but I can't find such a thing.
问题是 currentLocale() 是我编造的。我如何在 JDBC 连接的 Java 端做一些事情来为我拥有的 Connection 对象设置语言环境,我可以在一个简单的函数中在 Oracle 端读取它。理想情况下,这是 Oracle 的真正语言环境支持,但我找不到这样的东西。
I am using Oracle 10g and 11g.
我正在使用 Oracle 10g 和 11g。
回答by Simen S
Are you talking about the NLS_LANGUAGE
setting of the Oracle database? Would you (from the client side) like to dictate the usage of a particular NLS_LANGUAGE
by Oracle database?
你说NLS_LANGUAGE
的是oracle数据库的设置?您(从客户端)想指定NLS_LANGUAGE
Oracle 数据库对特定数据库的使用吗?
Then maybe this would work: Set Oracle NLS_LANGUAGE from java in a webapp
那么也许这会起作用:Set Oracle NLS_LANGUAGE from java in a webapp
If you want an "all american" session you could do you could do something like:
如果你想要一个“全美国人”会议,你可以这样做:
ALTER SESSION SET NLS_LANGUAGE= 'AMERICAN' NLS_TERRITORY= 'AMERICA'
NLS_CURRENCY= '$' NLS_ISO_CURRENCY= 'AMERICA'
NLS_NUMERIC_CHARACTERS= '.,' NLS_CALENDAR= 'GREGORIAN'
NLS_DATE_FORMAT= 'DD-MON-RR' NLS_DATE_LANGUAGE= 'AMERICAN'
NLS_SORT= 'BINARY'