Numeric Conversions: Oracle
Use the following functions in Oracle to convert to and from the supported numeric types:
TO_NUMBER(string
,format
) TO_BINARY_DOUBLE(string
,format
) TO_BINARY_FLOAT(string
,format
) TO_CHAR(number
,format
) TO_BINARY_DOUBLE(number
) TO_BINARY_FLOAT(number
) TO_NUMBER(number
)
Use TO_NUMBER and TO_CHAR (the only two functions available prior to Oracle Database 10g) to convert between NUMBER and VARCHAR2 (Table 1-9 lists the available numeric format elements):
SELECT TO_CHAR(1234.56,'C9G999D99') to_char, TO_NUMBER('1,234.56','9G999D99') from_char, TO_CHAR(123,'999V99') v_example FROM dual; TO_CHAR FROM_CHAR V_EXAMPLE ---------------- ---------------------- --------- USD1,234.56 1234.56 12300
Use TO_BINARY_FLOAT and TO_BINARY_DOUBLE to convert to the new 32- and 64-bit IEEE 754 floating-point types added in Oracle Database 10g. Also use these functions to convert values from one numeric type to another.
Table 1-9. Oracle’s numeric format elements
Element | Description |
---|---|
| Prefix: dollar sign
( |
| Location of comma.
Consider |
| Location of period.
Consider |
| Significant digit. Leading zeros. |
| Significant digit. Leading blanks. |
| Prefix: returns zero as blanks. |
| Location of ISO currency symbol. |
| Location of decimal point. |
| Suffix: use scientific notation. |
| Prefix: removes leading/trailing blanks. |
| Location of group separator. |
| Location of local currency symbol. |
| Suffix: trailing minus
( |
| Suffix: angle brackets
( |
Get SQL Pocket Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.