Oracle:时间数据的显示格式(to_char()、nls_date_format)
在使用Oracle的过程中,遇到时间类型的数据的时候,默认只有“日-月-年”的输出,没有更详细的信息。
如果你不想每次都通过“to_char()”做转换,你还可以通过修改数据库的初始化参数“nls_date_format”来达成效果。
具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
[oracle@oracle-db dbs]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jan 9 05:21:27 2016 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production With the Partitioning, OLAP and Data Mining options SQL> select name,created from v$database; NAME CREATED --------- --------- EDENDB1 07-JAN-16 SQL> SQL> select name,to_char(created,'yyyy-mm-dd hh24:mi:ss') "created" from v$database; NAME created --------- ------------------- EDENDB1 2016-01-07 03:15:27 SQL> SQL> show parameter nls_date_format; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ nls_date_format string SQL> SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; Session altered. SQL> show parameter nls_date_format; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ nls_date_format string SQL> SQL> select name,created from v$database; NAME CREATED --------- ------------------- EDENDB1 2016-01-07 03:15:27 SQL> |
——————————————————————
Done。