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('20070711','yyyy-mm-dd hh24:mi:ss') from dual;
select to_date('20070711','yyyy-mm-dd hh24:mi:ss') from dual
                   *
ERROR at line 1:
ORA-01861: literal does not match format string


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


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

TO_DATE('20070711','
-------------------
2007-07-11 00:00:00

SQL>

-----------------------------------以上sql从网上找到的,但是在这个数据库上怎么与上面的结果截然不同呢?
SQL> select to_date('20070711','yyyy-mm-dd hh24:mi:ss') from dual;

TO_DATE('20070711','YYYY-MM-DD
------------------------------
2007-7-11

SQL> select to_date('20070711','yyyy-mm-dd') from dual;

TO_DATE('20070711','YYYY-MM-DD
------------------------------
2007-7-11

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

TO_DATE('20070711','YYYYMMDD')
------------------------------
2007-7-11

SQL> select sysdate from dual;

SYSDATE
-----------
2007-7-12 1

SQL>

aix   db9.2.0.6

posted @ 2007-07-12 15:18  dbblog  阅读(7528)  评论(0编辑  收藏  举报