跳到主要内容
跳到主要内容

REVERSE

reverse

description

Syntax

VARCHAR reverse(VARCHAR str)
ARRAY<T> reverse(ARRAY<T> arr)

将字符串或数组反转,返回的字符串或者数组的顺序和原来的顺序相反。

example

mysql> SELECT REVERSE('hello');
+------------------+
| REVERSE('hello') |
+------------------+
| olleh |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT REVERSE('你好');
+------------------+
| REVERSE('你好') |
+------------------+
| 好你 |
+------------------+
1 row in set (0.00 sec)

mysql> select k1, k2, reverse(k2) from array_test order by k1;
+------+-----------------------------+-----------------------------+
| k1 | k2 | reverse(`k2`) |
+------+-----------------------------+-----------------------------+
| 1 | [1, 2, 3, 4, 5] | [5, 4, 3, 2, 1] |
| 2 | [6, 7, 8] | [8, 7, 6] |
| 3 | [] | [] |
| 4 | NULL | NULL |
| 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [1, 2, 3, 4, 5, 4, 3, 2, 1] |
| 6 | [1, 2, 3, NULL] | [NULL, 3, 2, 1] |
| 7 | [4, 5, 6, NULL, NULL] | [NULL, NULL, 6, 5, 4] |
+------+-----------------------------+-----------------------------+

mysql> select k1, k2, reverse(k2) from array_test01 order by k1;
+------+-----------------------------------+-----------------------------------+
| k1 | k2 | reverse(`k2`) |
+------+-----------------------------------+-----------------------------------+
| 1 | ['a', 'b', 'c', 'd'] | ['d', 'c', 'b', 'a'] |
| 2 | ['e', 'f', 'g', 'h'] | ['h', 'g', 'f', 'e'] |
| 3 | [NULL, 'a', NULL, 'b', NULL, 'c'] | ['c', NULL, 'b', NULL, 'a', NULL] |
| 4 | ['d', 'e', NULL, ' '] | [' ', NULL, 'e', 'd'] |
| 5 | [' ', NULL, 'f', 'g'] | ['g', 'f', NULL, ' '] |
+------+-----------------------------------+-----------------------------------+

keywords

REVERSE, ARRAY