snippetMinor
Setting NLS params in logon trigger don't work in oracle 11g
Viewed 0 times
params11gtriggerlogonsettingworkoraclenlsdon
Problem
We have a trigger setup so that when a specific user logs in, their NLS session parameters are modified. This used to work on Oracle 10g. We've just migrated to Oracle 11g RAC, and the session parameters are no longer persisting. To explain, I've pasted a session that shows the NLS_DATE_FORMAT not being used properly.
This is the trigger we're using:
The formats above are not default, so they appear to change on login.
Please help. I've been tearing my hair out for 13 h
This is the trigger we're using:
create or replace
TRIGGER schmea.nls_tr
AFTER logon ON DATABASE
BEGIN
execute immediate 'ALTER SESSION SET NLS_DATE_FORMAT = ''YYYY-MM-DD HH24:MI:SS'' NLS_TIMESTAMP_FORMAT = ''YYYY-MM-DD HH24:MI:SS.FF'' NLS_TERRITORY = ''AMERICA''';
END;The formats above are not default, so they appear to change on login.
SQL> select * from nls_session_parameters where parameter = 'NLS_TIMESTAMP_FORMAT' or parameter = 'NLS_DATE_FORMAT';
PARAMETER
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_DATE_FORMAT
YYYY-MM-DD HH24:MI:SS
NLS_TIMESTAMP_FORMAT
YYYY-MM-DD HH24:MI:SS.FF
SQL> select count(*) from TABLE where start_date > '2012-06-10 00:00:00';
select count(*) from TABLE where start_date > '2012-06-10 00:00:00'
*
ERROR at line 1:
ORA-12801: error signaled in parallel query server P024, instance
[domain.com]:[instance] (1)
ORA-01861: literal does not match format string
SQL> alter session set NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
Session altered.
SQL> select count(*) from TABLE where start_date > '2012-06-10 00:00:00';
COUNT(*)
----------
4901
SQL> select * from nls_session_parameters where parameter = 'NLS_TIMESTAMP_FORMAT' or parameter = 'NLS_DATE_FORMAT';
PARAMETER
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
NLS_DATE_FORMAT
YYYY-MM-DD HH24:MI:SS
NLS_TIMESTAMP_FORMAT
YYYY-MM-DD HH24:MI:SS.FFPlease help. I've been tearing my hair out for 13 h
Solution
Changing the order of the SET seemed to make a difference, as it is working now.
I don't really like this solution, as I still don't understand exactly why changing the order should matter. Perhaps the TERRITORY isn't being set correctly, but it was already the default so we're not TOO worried right now.
Also, django does do a
create or replace
TRIGGER schema.django_nls_tr
AFTER logon ON DATABASE
BEGIN
execute immediate 'ALTER SESSION SET NLS_TERRITORY = ''AMERICA'' NLS_DATE_FORMAT = ''YYYY-MM-DD HH24:MI:SS'' NLS_TIMESTAMP_FORMAT = ''YYYY-MM-DD HH24:MI:SS.FF''';
END;I don't really like this solution, as I still don't understand exactly why changing the order should matter. Perhaps the TERRITORY isn't being set correctly, but it was already the default so we're not TOO worried right now.
Also, django does do a
TO_TIMESTAMP. It expects most date fields to be TIMESTAMP(6) but we had it pointed at a legacy db with DATE type fields. The NLS shouldn't matter too dramatically in standard deployments.Code Snippets
create or replace
TRIGGER schema.django_nls_tr
AFTER logon ON DATABASE
BEGIN
execute immediate 'ALTER SESSION SET NLS_TERRITORY = ''AMERICA'' NLS_DATE_FORMAT = ''YYYY-MM-DD HH24:MI:SS'' NLS_TIMESTAMP_FORMAT = ''YYYY-MM-DD HH24:MI:SS.FF''';
END;Context
StackExchange Database Administrators Q#19025, answer score: 2
Revisions (0)
No revisions yet.