Menu
Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

STRTOL Function

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

Copy
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 is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. 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 is 16, the string can optionally begin with '0x'.

base

Integer between 2 and 36.

Return Type

BIGINT. If num_string is null, returns NULL.

Examples

The following examples convert string and base value pairs to integers:

Copy
select strtol('0xf',16); strtol -------- 15 (1 row) select strtol('abcd1234',16); strtol ------------ 2882343476 (1 row) select strtol('1234567', 10); strtol --------- 1234567 (1 row) select strtol('1234567', 8); strtol -------- 342391 (1 row) select strtol('110101', 2); strtol -------- 53 select strtol('\0', 2); strtol -------- 0