{ “title”: “STRRIGHT”, “language”: “en”, “description”: “The STRRIGHT function returns a specified number of characters from the right side of a string. The length is measured in UTF8 characters.” }

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 right extraction
SELECT STRRIGHT('Hello doris', 5), RIGHT('Hello doris', 5);
+----------------------------+------------------------+
| STRRIGHT('Hello doris', 5) | RIGHT('Hello doris', 5) |
+----------------------------+------------------------+
| doris                      | doris                  |
+----------------------------+------------------------+
  1. Different extraction lengths
SELECT STRRIGHT('Hello World', 3), STRRIGHT('Hello World', 8);
+-----------------------------+-----------------------------+
| STRRIGHT('Hello World', 3)  | STRRIGHT('Hello World', 8)  |
+-----------------------------+-----------------------------+
| rld                         | lo World                    |
+-----------------------------+-----------------------------+
  1. NULL value handling
SELECT STRRIGHT(NULL, 5), STRRIGHT('Hello doris', NULL);
+-------------------+-------------------------------+
| STRRIGHT(NULL, 5) | STRRIGHT('Hello doris', NULL) |
+-------------------+-------------------------------+
| NULL              | NULL                          |
+-------------------+-------------------------------+
  1. Empty string and zero length
SELECT STRRIGHT('', 5), STRRIGHT('Hello World', 0);
+-------------------+-----------------------------+
| STRRIGHT('', 5)   | STRRIGHT('Hello World', 0)  |
+-------------------+-----------------------------+
|                   |                             |
+-------------------+-----------------------------+
  1. Negative length handling
SELECT STRRIGHT('Hello doris', -7), STRRIGHT('Hello doris', -5);
+-----------------------------+-----------------------------+
| STRRIGHT('Hello doris', -7) | STRRIGHT('Hello doris', -5) |
+-----------------------------+-----------------------------+
| doris                       | o doris                     |
+-----------------------------+-----------------------------+
  1. Length exceeds string length
SELECT STRRIGHT('ABC', 10), STRRIGHT('short', 20);
+---------------------+-----------------------+
| STRRIGHT('ABC', 10) | STRRIGHT('short', 20) |
+---------------------+-----------------------+
| ABC                 | short                 |
+---------------------+-----------------------+
  1. UTF-8 multi-byte characters
SELECT STRRIGHT('ṭṛì ḍḍumai hello', 5), STRRIGHT('ṭṛì ḍḍumai hello', 11);
+----------------------------------+-----------------------------------+
| STRRIGHT('ṭṛì ḍḍumai hello', 5)  | STRRIGHT('ṭṛì ḍḍumai hello', 11) |
+----------------------------------+-----------------------------------+
| hello                            | umai hello                       |
+----------------------------------+-----------------------------------+
  1. Numeric string handling
SELECT STRRIGHT('123456789', 3), STRRIGHT('ID_987654321', 6);
+----------------------------+-------------------------------+
| STRRIGHT('123456789', 3)   | STRRIGHT('ID_987654321', 6)   |
+----------------------------+-------------------------------+
| 789                        | 654321                        |
+----------------------------+-------------------------------+
  1. Email domain extraction
SELECT STRRIGHT('user@example.com', 11), STRRIGHT('admin@company.org.cn', 14);
+----------------------------------+--------------------------------------+
| STRRIGHT('user@example.com', 11) | STRRIGHT('admin@company.org.cn', 14) |
+----------------------------------+--------------------------------------+
| example.com                      | company.org.cn                      |
+----------------------------------+--------------------------------------+

Keywords

STRRIGHT, RIGHT