现在的位置: 首页 > 综合 > 正文

oracle中日期格式’yyyy-mm-dd’和’yyyymmdd’的区别

2018年02月15日 ⁄ 综合 ⁄ 共 631字 ⁄ 字号 评论关闭
oracle中日期格式'yyyy-mm-dd'和'yyyymmdd'的区别
 

对于年月日中"日"是个位的情况下,处理不一样,'yyyymmdd'格式没问题,而式'yyyy-mm-dd'格式则不行,请看:

SQL> alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';

Session altered.

SQL> select to_date('2007059','yyyy-mm-dd hh24:mi:ss') from dual;
select to_date('2007059','yyyy-mm-dd hh24:mi:ss') from dual
                 *
ERROR at line 1:
ORA-01861: literal does not match format string

SQL> select to_date('2007059','yyyy-mm-dd') from dual;
select to_date('2007059','yyyy-mm-dd') from dual
                 *
ERROR at line 1:
ORA-01861: literal does not match format string

SQL> select to_date('2007059','yyyymmdd')   from dual;

TO_DATE('2007059','
-------------------
2007-05-09 00:00:00

抱歉!评论已关闭.