Oracle SQL: TO_CHAR and TO_NUMBER 笔记

时间:2022-05-09 00:28:38
(1)
select TO_CHAR(123.56,'999.9') from dual; will return 123.6
select TO_NUMBER('123.56','999.9') from dual; will fail because of error "ORA-01722: invalid number"

(2)
select TO_CHAR(123.56,'999') from dual; will return 124
select TO_NUMBER(123.56,'999') from dual; will fail because of error "ORA-01722: invalid number"

(3)
select TO_CHAR(123.56,'9999.99') from dual;will return 123.56
select TO_NUMBER('123.56','9999.99') from dual; will return 123.56

(4)
select TO_CHAR(123.56,'9999') from dual; will return 124
select TO_NUMBER('123.56','9999') from dual; will fail because of error "ORA-01722: invalid number"

(5)
select TO_CHAR(123.56,'99') from dual; will return ###
select TO_NUMBER(123.56,'99') from dual; will fail because of error "ORA-01722: invalid number"

(6)
select TO_CHAR(123.56,'999.99') from dual; will return 123.56
select TO_NUMBER(123.56,'999.99') from dual; will return 123.56