Change the date output format (nls_date_format)

Source: Internet
Author: User
Changing the date output format (nls_date_format) in sqlplus)

In the work, we encounter the use of spool to export data, where there is a date format field, because the format of each column, you do not want to use to_char to format the date, in addition, if to_char is used, all columns must be written in the SELECT statement .....................

In the work, we encounter the use of spool to export data, where there is a date format field, because the format of each column, you do not want to use to_char to format the date, in addition, if to_char is used, all columns must be written in the SELECT statement. In win, the default format is dd-mm-yy, as follows:
SQL> select sysdate from dual;

Sysdate
----------
Month 21-12-04

The format of the date field in the database is yyyy-mm-dd hh24miss. The exported data must also be in this format. You can set nls_date_format as follows:
1. Use alter session to modify
SQL> alter session set nls_date_format = 'yyyy-mm-dd hh24: MI: ss ';
SQL> select sysdate from dual;

Sysdate
-------------------
2004-12-21 14:44:24

2. Set nls_date_format iN OS
Open a console window
C:> set nls_date_format = YYYY-MM-DD hh24: MI: SS // Note: here the YYYY-MM-DD hh24: MI: SS cannot be enclosed by quotation marks, but must be added to Unix systems

SQL> select sysdate from dual;

Sysdate
-------------------
2004-12-21 14:45:44

After this change is only valid for the current Console window, if you do not want to set every time, modify the system/user environment variables, add a new nls_date_format variable, value for YYYY-MM-DD hh24: MI: SS
Open a console window
SQL> select sysdate from dual;

Sysdate
-------------------
2004-12-21 14:46:15

In this way, select * From tabs in spool.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.