Monday, April 14, 2008

Change NLS_DATE_FORMAT Parmanently

The parameter NLS_DATE_FORMAT specifies the default date format to use with the TO_CHAR and TO_DATE functions. The default value of this parameter is determined by NLS_TERRITORY.

This parameter is modifiable and can be set through ALTER SESSION parameter. If you start your database with spfile then you can set this parameter by ALTER SYSTEM SET command.

So the setting of this parameter by ALTER SESSION is transient. If we want to make it permanent then then following steps should be performed.

1)Create pfile='1.txt' from spfile;
2)Edit pfile 1.txt and entry NLS_DATE_FORMAT as you wish the format.
3.start the database with pfile and create spfile from pfile.
4)Shutdown and Start the database.
5)Now query. Date will be shown as of format specified in NLS_DATE_FORMAT.


Example:
----------

1)SQL> create pfile='/oradata/1.txt' from spfile;

On unix system,
2)SQL> !vi /oradata/1.txt and entry,
*.nls_date_format='DD-MM-YY'

On windows just open pfile with any editor software like notepad and give an entry of nls_date_format.
3)SQL> startup pfile='/oradata/1.txt'

4)SQL> select sysdate from dual;
SYSDATE
--------
15-04-08

5)SQL> create spfile from pfile='/oradata/1.txt';

6)SQL> shutdown imemdiate;

7)SQL> startup

8)SQL> select sysdate from dual;

SYSDATE
--------
15-04-08

1 comment:

  1. can u please tell about the second step.I didnt understand the command

    ReplyDelete