substr

Purpose

Extracts a particular portion of the extracted result string.

Syntax

substr(string, start [, length])

Arguments

The function accepts three arguments. The first two arguments are required, the third argument is optional:

  1. string is a string the substring will be extracted from;

  2. start is the start position of the substring in characters. The first character has a position of 1. If position is 0, it is treated as 1. If start position is negative, it is counted from the end of the string;

  3. length is the length of the substring in characters. If omitted, the whole string will be returned from the start position.

Returned Value

A string value.

If the input value is null or the arguments are invalid, a null value is returned.

Examples

substr("USA", 1, 2) = substr("USA", 0, 2) returns "US".

substr("Japan", -3, 2) returns "pa".

substr("Canada", 2) returns "anada".

substr("Canada", -2) returns "da".