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?
Example:
SELECT TO_CHAR(0.56) FROM DUAL;
/* Result = .56 */
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s the default formatting that Oracle provides. If you want leading zeros on output, you’ll need to explicitly provide the format. Use:
or even:
The same is true for trailing zeros:
The general form of the TO_CHAR conversion function is:
TO_CHAR(number, format)