Skip to main content

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​

ParameterDescription
<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​

  1. Basic usage
SELECT strright('Hello doris', 5);
+----------------------------+
| strright('Hello doris', 5) |
+----------------------------+
| doris |
+----------------------------+
  1. Handling negative length
SELECT strright('Hello doris', -7);
+-----------------------------+
| strright('Hello doris', -7) |
+-----------------------------+
| doris |
+-----------------------------+
  1. Handling NULL parameter
SELECT strright('Hello doris', NULL);
+-------------------------------+
| strright('Hello doris', NULL) |
+-------------------------------+
| NULL |
+-------------------------------+
  1. Handling NULL string
SELECT strright(NULL, 5);
+-------------------+
| strright(NULL, 5) |
+-------------------+
| NULL |
+-------------------+