Pl/Sql Trigger for changing default date format in oracle

核能气质少年 提交于 2019-12-11 08:07:09

问题


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_FORMAT or implicitly with the initialization parameter NLS_TERRITORY. You can change the default datetime formats for your session with the ALTER SESSION statement.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!