Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

STRTOL function

Focus mode
STRTOL function - Amazon Redshift

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 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, 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 | +--------+

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.