Oracle-为什么将数字的前导零转换为TO_CHAR时会消失 [英] Oracle - Why does the leading zero of a number disappear when converting it TO_CHAR
本文介绍了Oracle-为什么将数字的前导零转换为TO_CHAR时会消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Oracle中,将带有前导零的数字转换为字符时,为什么会消失?此逻辑是Oracle特定的还是SQL特定的?
In Oracle, when converting a number with a leading zero to a character, why does the leading number disappear? Is this logic Oracle specific, or specific to SQL?
示例:
SELECT TO_CHAR(0.56) FROM DUAL;
/* Result = .56 */
推荐答案
这是Oracle提供的默认格式.如果要在输出中使用前导零,则需要显式提供格式.使用:
It's the default formatting that Oracle provides. If you want leading zeros on output, you'll need to explicitly provide the format. Use:
SELECT TO_CHAR(0.56,'0.99') FROM DUAL;
甚至:
SELECT TO_CHAR(.56,'0.99') FROM DUAL;
尾随零也是如此:
SQL> SELECT TO_CHAR(.56,'0.990') val FROM DUAL;
VAL
------
0.560
TO_CHAR转换函数的一般形式为:
The general form of the TO_CHAR conversion function is: