Tuesday 22 November 2016

Oracle / PLSQL: TO_CHAR Function Number Formatting

Number Formatting
      Character       Example       Explanation            9               9999          Each character represents a place holder for digits.      0               999.00        Used for leading or trailing zeros.           $               $9999         prefixes the number with a dollar sign.           S               S9999         Useful for positive and negative numbers in query results.           PR              9999PR        Displays negative numbers in angle brackets.           D or .          99D99, 99.99  Places a decimal point in the place where the D or. is.           ,               9,999         Places a comma in the place where the , is.           RN or rn        RN            Displays roman numerals, in upper-or lowercase depending on the case of the format mask.           DATE            date          Assumes the number in a Julian date, and displays the resulting value in MM/DD/YY format.      

TO_CHAR(-12345.67, '99,999.99PR'): negative value in angle brackets
SQL>  SQL>  SQL>  SQL> SELECT TO_CHAR(-12345.67, '99,999.99PR') FROM dual;    TO_CHAR(-12  -----------  <12,345.67>    SQL>  

TO_CHAR(12345.67, '99999V99'): shift specified number of digits
SQL>  SQL>  SQL> SELECT TO_CHAR(12345.67, '99999V99') FROM dual;    TO_CHAR(  --------   1234567    SQL>  SQL>

TO_CHAR(12345.67, 'U99,999.99')
SQL>  SQL>  SQL> SELECT TO_CHAR(12345.67, 'U99,999.99') FROM dual;    TO_CHAR(12345.67,'U9  --------------------            $12,345.67    SQL>

No comments:

Post a Comment