Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.
Syntax
STRTOL(num_string, base)
Arguments
- num_string
-
String expression of a number to be converted. If num_string is empty (
''
) or begins with the null character ('\0'
), the converted value is0
. If num_string is a column containing a NULL value, STRTOL returnsNULL
. The string can begin with any amount of white space, optionally followed by a single plus '+
' or minus '-
' sign to indicate positive or negative. The default is '+
'. If base is16
, the string can optionally begin with '0x
'. - base
-
INTEGER
between 2 and 36.
Return type
- BIGINT
-
If num_string is null, the function returns
NULL
.
Examples
To convert string and base value pairs to integers, use the following examples.
SELECT STRTOL('0xf',16);
+--------+
| strtol |
+--------+
| 15 |
+--------+
SELECT STRTOL('abcd1234',16);
+------------+
| strtol |
+------------+
| 2882343476 |
+------------+
SELECT STRTOL('1234567', 10);
+---------+
| strtol |
+---------+
| 1234567 |
+---------+
SELECT STRTOL('1234567', 8);
+--------+
| strtol |
+--------+
| 342391 |
+--------+
SELECT STRTOL('110101', 2);
+--------+
| strtol |
+--------+
| 53 |
+--------+
SELECT STRTOL('\0', 2);
+--------+
| strtol |
+--------+
| 0 |
+--------+