Purpose
This function converts a string of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, BINARY_FLOAT, or BINARY_DOUBLE data type to a value of the NUMBER data type.
Syntax
TO_NUMBER(expr [, fmt [, 'nlsparam' ] ])
Parameters
Parameter |
Description |
|---|---|
| expr | A value of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, BINARY_FLOAT, or BINARY_DOUBLE data type. |
| fmt | The format model of expr. Optional. Note expr must be within the range of fmt. For example: TO_NUMBER('$123456.78','$999999999.999'). |
| nlsparam | The language used for the returned data. Optional. |
Return type
NUMBER
Examples
Convert the string
0123456to a number.obclient> SELECT TO_NUMBER('0123456') FROM DUAL; +----------------------+ | TO_NUMBER('0123456') | +----------------------+ | 123456 | +----------------------+ 1 row in setConvert the hexadecimal number
16fto a decimal number.obclient> SELECT TO_NUMBER('16f','xxx') FROM DUAL; +------------------------+ | TO_NUMBER('16F','XXX') | +------------------------+ | 367 | +------------------------+ 1 row in set
