reverse

description

Syntax

  1. VARCHAR reverse(VARCHAR str)
  2. ARRAY<T> reverse(ARRAY<T> arr)

The REVERSE() function reverses a string or array and returns the result.

notice

For the array type, only supported in vectorized engine

example

  1. mysql> SELECT REVERSE('hello');
  2. +------------------+
  3. | REVERSE('hello') |
  4. +------------------+
  5. | olleh |
  6. +------------------+
  7. 1 row in set (0.00 sec)
  8. mysql> SELECT REVERSE('你好');
  9. +------------------+
  10. | REVERSE('你好') |
  11. +------------------+
  12. | 好你 |
  13. +------------------+
  14. 1 row in set (0.00 sec)
  15. mysql> set enable_vectorized_engine=true;
  16. mysql> select k1, k2, reverse(k2) from array_test order by k1;
  17. +------+-----------------------------+-----------------------------+
  18. | k1 | k2 | reverse(`k2`) |
  19. +------+-----------------------------+-----------------------------+
  20. | 1 | [1, 2, 3, 4, 5] | [5, 4, 3, 2, 1] |
  21. | 2 | [6, 7, 8] | [8, 7, 6] |
  22. | 3 | [] | [] |
  23. | 4 | NULL | NULL |
  24. | 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [1, 2, 3, 4, 5, 4, 3, 2, 1] |
  25. | 6 | [1, 2, 3, NULL] | [NULL, 3, 2, 1] |
  26. | 7 | [4, 5, 6, NULL, NULL] | [NULL, NULL, 6, 5, 4] |
  27. +------+-----------------------------+-----------------------------+
  28. mysql> select k1, k2, reverse(k2) from array_test01 order by k1;
  29. +------+-----------------------------------+-----------------------------------+
  30. | k1 | k2 | reverse(`k2`) |
  31. +------+-----------------------------------+-----------------------------------+
  32. | 1 | ['a', 'b', 'c', 'd'] | ['d', 'c', 'b', 'a'] |
  33. | 2 | ['e', 'f', 'g', 'h'] | ['h', 'g', 'f', 'e'] |
  34. | 3 | [NULL, 'a', NULL, 'b', NULL, 'c'] | ['c', NULL, 'b', NULL, 'a', NULL] |
  35. | 4 | ['d', 'e', NULL, ' '] | [' ', NULL, 'e', 'd'] |
  36. | 5 | [' ', NULL, 'f', 'g'] | ['g', 'f', NULL, ' '] |
  37. +------+-----------------------------------+-----------------------------------+

keywords

  1. REVERSE, ARRAY