「MySQL」REVERSE関数で文字列を反転させる

環境
Windows10 64bit
MySQL 8.0.27
書式
REVERSE(文字列)
REVERSE関数を使用することで文字列を反転させます

使用例1
英字の文字列を反転させます

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql> SELECT REVERSE( 'ArkGame' ) result;
+---------+
| result |
+---------+
| emaGkrA |
+---------+
1 row in set (0.00 sec)
mysql> SELECT REVERSE( 'ArkGame' ) result; +---------+ | result | +---------+ | emaGkrA | +---------+ 1 row in set (0.00 sec)
mysql> SELECT REVERSE( 'ArkGame' ) result;
+---------+
| result  |
+---------+
| emaGkrA |
+---------+
1 row in set (0.00 sec)

使用例2
日本語の文字列を反転させます

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql> SELECT REVERSE('山田太郎') result;
+----------+
| result |
+----------+
| 郎太田山 |
+----------+
1 row in set (0.01 sec)
mysql> SELECT REVERSE('山田太郎') result; +----------+ | result | +----------+ | 郎太田山 | +----------+ 1 row in set (0.01 sec)
mysql> SELECT REVERSE('山田太郎') result;
+----------+
| result   |
+----------+
| 郎太田山 |
+----------+
1 row in set (0.01 sec)

使用例3
引数に数値が指定された場合

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql> SELECT REVERSE('-56.432') result;
+---------+
| result |
+---------+
| 234.65- |
+---------+
1 row in set (0.00 sec)
mysql> SELECT REVERSE('-56.432') result; +---------+ | result | +---------+ | 234.65- | +---------+ 1 row in set (0.00 sec)
mysql> SELECT REVERSE('-56.432') result;
+---------+
| result  |
+---------+
| 234.65- |
+---------+
1 row in set (0.00 sec)

使用例4
引数にNULLが指定された場合

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mysql> SELECT REVERSE(NULL) result;
+----------------+
| result |
+----------------+
| NULL |
+----------------+
1 row in set (0.00 sec)
mysql> SELECT REVERSE(NULL) result; +----------------+ | result | +----------------+ | NULL | +----------------+ 1 row in set (0.00 sec)
mysql> SELECT REVERSE(NULL) result;
+----------------+
| result         |
+----------------+
| NULL           |
+----------------+
1 row in set (0.00 sec)

 

MySQL

Posted by arkgame