问题
i want to ensure that every time i logon the date format is changed from '24-Apr-2014' to '24/04/2014'
For that I created a pl/sql trigger as follows
CREATE OR REPLACE TRIGGER CHANGE_DATE_FORMAT
AFTER LOGON ON DATABASE
BEGIN
ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY';
END;
/
However i am not logged on as sysdba so perhaps thats why i get the error
SQL> @C:/pl/dateTrigger.sql AFTER LOGON ON DATABASE * ERROR at line 2: ORA-01031: insufficient privileges
What can i do to ensure that date format is changed permanently?
回答1:
Your error means you are not allowed to create such a trigger. But your on the wrong track. You must set the default at database level.
Setting Default Datetime Format Template
From Oracle documentation
The default datetime format template is specified either explicitly with the initialization parameter
NLS_DATE_FORMATor implicitly with the initialization parameterNLS_TERRITORY. You can change the default datetime formats for your session with theALTER SESSIONstatement.
Then for your case this format must be set in your database initialization parameters.
To check you have the right value in current session:
select value from v$parameter where upper(name)='NLS_DATE_FORMAT';
来源:https://stackoverflow.com/questions/23276366/pl-sql-trigger-for-changing-default-date-format-in-oracle