STRRIGHT
Descriptionβ
The STRRIGHT function returns a specified number of characters from the right side of a string. The length is measured in UTF8 characters.
Aliasβ
RIGHT
Syntaxβ
STRRIGHT(<str>, <len>)
Parametersβ
Parameter | Description |
---|---|
<str> | The string to extract from. Type: VARCHAR |
<len> | The number of characters to return. Type: INT |
Return Valueβ
Returns VARCHAR type, representing the extracted substring.
Special cases:
- Returns NULL if any argument is NULL
- If len is negative, returns the substring starting from the abs(len)th character from the right
- Returns the entire string if len is greater than the string length
Examplesβ
- Basic usage
SELECT strright('Hello doris', 5);
+----------------------------+
| strright('Hello doris', 5) |
+----------------------------+
| doris |
+----------------------------+
- Handling negative length
SELECT strright('Hello doris', -7);
+-----------------------------+
| strright('Hello doris', -7) |
+-----------------------------+
| doris |
+-----------------------------+
- Handling NULL parameter
SELECT strright('Hello doris', NULL);
+-------------------------------+
| strright('Hello doris', NULL) |
+-------------------------------+
| NULL |
+-------------------------------+
- Handling NULL string
SELECT strright(NULL, 5);
+-------------------+
| strright(NULL, 5) |
+-------------------+
| NULL |
+-------------------+