日期:2014-05-16 浏览次数:20538 次
BYS@bys1>select sysdate from dual;
SYSDATE2013/10/25 09:40:31
BYS@bys1>select to_date('2013/10/25 09:40:31') from dual;
TO_DATE('2013/10/25
-------------------
2013/10/25 09:40:31
不能使用&,&表示传入变量。不能使用数字或字母字符。
BYS@bys1>select to_date('2013-02-21 10:00:00') from dual;
TO_DATE('2013-02-21
-------------------
2013/02/21 10:00:00
BYS@bys1>select to_date('2013-02#21 10:00+00') from dual;
TO_DATE('2013-02#21
-------------------
2013/02/21 10:00:00
BYS@bys1>select to_date('2013-02a21 10:00+00') from dual;
select to_date('2013-02a21 10:00+00') from dual
*
ERROR at line 1:
ORA-01861: literal does not match format string
BYS@bys1>select to_date('2013-02921 10:00+00') from dual;
select to_date('2013-02921 10:00+00') from dual
*
ERROR at line 1:
ORA-01861: literal does not match format string
BYS@bys1>select to_date('2013-02@21 10:00+00') from dual;
TO_DATE('2013-02@21
-------------------
2013/02/21 10:00:00
把最后的表示秒的字符省略,可以正常显示。
BYS@bys1>select to_date('2013-02@21 10:00') from dual;
TO_DATE('2013-02@21
-------------------
2013/02/21 10:00:00
把最后的表示秒的字符及表示具体几号的字符省略,报错。
BYS@bys1>select to_date('2013-@21 10:00') from dual;
select to_date('2013-@21 10:00') from dual
*
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected
只给出10点,分和秒未给出,以0代替。
BYS@bys1>select to_date('2013-02@21 10') from dual;
TO_DATE('2013-02@21
-------------------
2013/02/21 10:00:00
只给出日期的字段,时、分、秒用0来代替。
BYS@bys1>select to_date('2013-02@21 ') from dual;
TO_DATE('2013-02@21
-------------------
2013/02/21 00:00:00
只给出年-月,未给几号,报错。
BYS@bys1>select to_date('2013-02 ') from dual;
select to_date('2013-02 ') from dual
*
ERROR at line 1:
ORA-01840: input value not long enough for date format
BYS@bys1>select to_date('2013-02$1 ') from dual;
TO_DATE('2013-02$1'
-------------------
2013/02/01 00:00:00
BYS@bys1>select sysdate from dual;
SYSDATE
---------
25-OCT-13
注意列宽,以免不能显示全。
BYS@bys1>col aa for a20
BYS@bys1>select to_date('2013-02-21 10:00:00','yyyy-mm-dd hh24:mi:ss') aa from dual;
AA
--------------------
21-FEB-13
不指定格式会报错:
B