SUBSTR

Syntax

SUBSTR(str, position [, length])

Overview

SUBSTR is a function that extracts and returns a string of length length from position position within str.

Parameter

Parameter
Description

str

Arbitrary operation that returns a string.

When values of numeric types such as smallint, integer, bigint, decimal, or numeric are input, they are automatically converted to strings and processed as string values.

position

Arbitrary operation returning an integer value. If position is less than 0, it is extracted from the end of str.

length

Arbitrary operation returning an integer value. If length is not specified, the string is extracted from the position of str to the end. If length is less than 1, returns NULL.

Example

SELECT SUBSTR('ABCDEFG', 3, 2), SUBSTR('ABCDEFG', -3, 2);
 substr | substr 
--------+--------
 CD     | EF

Last updated