APPEND_TRAILING_CHAR_IF_ABSENT
Description
Used to add a specific character (such as a space, a specific symbol, etc.) to the end of a string if the character does not exist at the end of the string. The function is to ensure that the string ends with a specific character.
Syntax
APPEND_TRAILING_CHAR_IF_ABSENT ( <str> , <trailing_char> )
Parameters
| Parameters | Description |
|---|---|
<str> | Target string to be judged |
<trailing_char> | Character to be added to the end of the string (if the character does not exist) |
Return value
Parameters The string after concatenation of <str> and <trailing_char> (if <trailing_char> does not exist in <str>)
Example
- Basic usage: Add character when it doesn't exist
SELECT APPEND_TRAILING_CHAR_IF_ABSENT('a', 'c');
+------------------------------------------+
| APPEND_TRAILING_CHAR_IF_ABSENT('a', 'c') |
+------------------------------------------+
| ac |
+------------------------------------------+
- Character already exists, don't add
SELECT APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'c');
+-------------------------------------------+
| APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'c') |
+-------------------------------------------+
| ac |
+-------------------------------------------+
- Empty string handling
SELECT APPEND_TRAILING_CHAR_IF_ABSENT('', '/');
+-----------------------------------------+
| APPEND_TRAILING_CHAR_IF_ABSENT('', '/') |
+-----------------------------------------+
| / |
+-----------------------------------------+
- NULL value handling
SELECT APPEND_TRAILING_CHAR_IF_ABSENT(NULL, 'c');
+-------------------------------------------+
| APPEND_TRAILING_CHAR_IF_ABSENT(NULL, 'c') |
+-------------------------------------------+
| NULL |
+-------------------------------------------+
- UTF-8 character
SELECT APPEND_TRAILING_CHAR_IF_ABSENT('acf', 'ṛ');
+----------------------------------------------+
| APPEND_TRAILING_CHAR_IF_ABSENT('acf', 'ṛ') |
+----------------------------------------------+
| acfṛ |
+----------------------------------------------+