Use JDBC to change the session parameters of Oracle Nls_date_format

Source: Internet
Author: User

Recent projects in addition to a problem, the scenario is probably this, the project was developed abroad, in the project development process using a large number of Oracle function To_date, but the developer did not write a second parameter.

So the project in the foreign server can be normal operation, but in the domestic server will not work properly.


By investigation, because the first parameter of the To_date function is YYYYMMDD and the second argument is null, the Nls_date_format parameter in session is used by default.

The database server is in English, so the default Nls_date_format is RR-MM-DD, and the client's parameters are used when connecting to the Oracle database server abroad

Overrides the server-side parameters. (This is based on Oracle's official documentation)

This initial value was overridden by a Client-side value if the client uses the Oracle JDBC driver or if the client is oci- Based and the Nls_lang client setting (environment variable) is defined. The initialization parameter value is, therefore, usually ignored.


However, the official document does not say how to do, so check the information, in the registry Software "Oracle under the key starting with the key under the string Value, Nls_date_format=yyyymmdd.

The experiment proves that this modification is valid for sqlplus, but it is not valid for Sqldeveloper. No effective methods for sqldeveloper have been found yet.

Second, for JDBC also did not find the way to set parameters, if you have a good way to give me a message.

But then again, I found a way to solve this problem, which is to create a trigger.

I created the following trigger:

CREATE OR REPLACE TRIGGER LOGINTRG
After LOGON on DATABASE
BEGIN
EXECUTE IMMEDIATE ' ALTER SESSION SET nls_date_format= ' rr/mm/dd ';
END LOGINTRG;

Note that SQL does not execute if the date is not formatted.


Use JDBC to change the session parameters of Oracle Nls_date_format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.