5

My query is

select TO_CHAR('03-JAN-2013', 'D') from dual;

but an error occured as

ORA-01722: invalid number
01722. 00000 -  "invalid number"
*Cause:    
*Action:

But when query changed as select TO_CHAR(sysdate, 'D') from dual;

Result is right answer 5.

I can't understand why it is behaving like this, please help me.

Thanks in advance

4

2 回答 2

3

请在选择之前将字符串转换为日期。

SELECT TO_CHAR(CAST('03-JAN-2013' AS DATE), 'D') FROM DUAL;

或者

SELECT TO_CHAR(TO_DATE('03-JAN-2013'), 'D') FROM DUAL;
于 2013-01-03T10:00:03.647 回答
2

在调用函数之前'03-JAN-2013',必须将字符串文字转换为数据类型:dateTO_CHAR

select TO_CHAR(to_date('03-JAN-2013', 'dd-MON-YYYY'), 'D') as res
 from dual

RES
-----
 5
于 2013-01-03T10:00:52.257 回答