Where to change the NLS_DATE_FORMAT in oracle 11g?

我们两清 提交于 2019-12-24 03:34:31

问题


i need to change the NLS_DATE_FORMAT in my Stored procedure.seems like its a session variable and where should i alter the variable mask.

should it be done in global declaration or elsewhere(i mean from frontend).


回答1:


If you want to change a NLS parameter in a procedure then you can use DBMS_SESSION.SET_NLS. Given an environment that looks like this:

SQL> select value
  2    from nls_session_parameters
  3   where parameter = 'NLS_DATE_FORMAT';

VALUE
------------------------------------------

DD-MON-RR

SQL> select sysdate from dual;

SYSDATE
---------
25-NOV-14

executing the procedure changes the format (note the triple single quotes):

SQL> begin
  2     dbms_session.set_nls('nls_date_format', '''yyyy-mm-dd''');
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> select sysdate from dual;

SYSDATE
----------
2014-11-25

Alternatively you can use dynamic SQL, EXECUTE IMMEDIATE, for instance:

SQL> begin
  2     execute immediate 'alter session set nls_date_format = ''yyyy-mm''';
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> select sysdate from dual;

SYSDATE
-------
2014-11

However, as Justin Cave notes this is highly unusual. If you're converting between datatypes you should always do this explicitly with an explicit format. In the case of dates the correct function to use is TO_DATE()



来源:https://stackoverflow.com/questions/27120420/where-to-change-the-nls-date-format-in-oracle-11g

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