如何更改 oracle jdbc 客户端的默认 nls_date_format
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/447608/
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
How to change default nls_date_format for oracle jdbc client
提问by Yoni
I have defined the global nls_date_format on Oracle 10.2 XE as follows:
我在 Oracle 10.2 XE 上定义了全局 nls_date_format 如下:
alter system set nls_date_format='YYYY-MM-DD HH24:MI:SS' scope=spfile;
When connecting on Windows, the clients override it with session specific format, so I need to run this line at the beginning of every session:
在 Windows 上连接时,客户端使用会话特定格式覆盖它,因此我需要在每个会话开始时运行此行:
alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
However, I have some custom code that I can't change (jdbc code, using ojdbc14.jar), so I can't execute this line when receiving the connection. Is there a way to change the default value of nls_date_format for all jdbc connections? Perhaps adding something to the connection string, or some environment variable that I can use?
但是,我有一些无法更改的自定义代码(jdbc 代码,使用 ojdbc14.jar),因此在接收连接时无法执行此行。有没有办法为所有 jdbc 连接更改 nls_date_format 的默认值?也许在连接字符串中添加一些东西,或者一些我可以使用的环境变量?
By the way, sqlplus and sqldeveloper also override the server's format with their own, but I found out how to change their defaults, so the problem is only with jdbc connections.
顺便说一句,sqlplus 和 sqldeveloper 也用自己的格式覆盖了服务器的格式,但我发现了如何更改它们的默认值,所以问题仅在于 jdbc 连接。
采纳答案by Yoni
Set nls date format in an after logon trigger
在登录后触发器中设置 nls 日期格式
回答by Yoni
Thanks, that worked for me. The trigger that I inserted is this:
谢谢,这对我有用。我插入的触发器是这样的:
CREATE OR REPLACE TRIGGER LOGINTRG
AFTER LOGON ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS''';
END LOGINTRG;