- Categories:
String & binary functions (Matching/Comparison)
RIGHT¶
Returns a rightmost substring of its input.
RIGHT(STR,N)
is equivalent to SUBSTR(STR,LENGTH(STR)-N+1,N)
.
- See also:
Syntax¶
RIGHT( <expr> , <length_expr> )
Arguments¶
expr
The expression for which you want the rightmost substring. The expression must evaluate to a
VARCHAR
orBINARY
value.length_expr
The length should be an expression that evaluates to an integer. It should specify:
The number of UTF-8 characters to return if the input is
VARCHAR
.The number of bytes to return if the input is
BINARY
.
The length should be greater than or equal to zero. If the length is a negative number, the function returns an empty string.
Returns¶
The data type of the returned value is the same as the data type of the input value (BINARY
or VARCHAR
).
Usage notes¶
If
length_expr
is greater than the length ofexpr
, then the function returnsexpr
.
Collation details¶
Collation applies to
VARCHAR
inputs. Collation does not apply if the input data type of the first parameter isBINARY
.No impact. Although collation is accepted syntactically, collations have no impact on processing. For example, languages with two-character and three-character letters (e.g. “dzs” in Hungarian, “ch” in Czech) still count those as two or three characters (not one character) for the length argument.
The collation of the result is the same as the collation of the input. This can be useful if the returned value is passed to another function as part of nested function calls.
Examples¶
SELECT RIGHT('ABCDEFG', 3);
---------------------+
RIGHT('ABCDEFG', 3) |
---------------------+
EFG |
---------------------+