RIGHT
functionsupportedCore SQL functionsReturns a rightmost substring of its input. RIGHT(STR, N) is equivalent to SUBSTR(STR, LENGTH(STR)-N+1, N). See also: LEFT , SUBSTR , SUBSTRING
Syntax
RIGHT( <string_expr> , <length_expr> )
Parameters
| Name | Required | Description |
|---|---|---|
string_expr | required | An expression that evaluates to a VARCHAR or BINARY value. |
length_expr | required | An expression that evaluates to an integer. It specifies: The number of UTF-8 characters to return if the input is a VARCHAR value. The number of bytes to return if the input is a BINARY value. Specify a length that is 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 string_expr (VARCHAR or BINARY). If any of the inputs are NULL, NULL is returned.
Usage notes
- If length_expr is greater than the length of expr, then the function returns expr.
Collation details
- Collation applies to VARCHAR inputs. Collation doesn’t apply if the input data type of the first parameter is BINARY. - No impact. Although collation is accepted syntactically, collations don’t affect processing. For example, two-character and three-character letters in languages (for example, “dzs” in Hungarian or “ch” in Czech) are still counted 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.