SinceVersion 1.2

convert_to

description

Syntax

convert_to(VARCHAR column, VARCHAR character)

It is used in the order by clause. eg: order by convert(column using gbk), Now only support character can be converted to ‘gbk’. Because when the order by column contains Chinese, it is not arranged in the order of Pinyin After the character encoding of column is converted to gbk, it can be arranged according to pinyin

example

  1. mysql> select * from class_test order by class_name;
  2. +----------+------------+-------------+
  3. | class_id | class_name | student_ids |
  4. +----------+------------+-------------+
  5. | 6 | asd | [6] |
  6. | 7 | qwe | [7] |
  7. | 8 | z | [8] |
  8. | 2 | | [2] |
  9. | 3 | | [3] |
  10. | 1 | | [1] |
  11. | 4 | | [4] |
  12. | 5 | | [5] |
  13. +----------+------------+-------------+
  14. mysql> select * from class_test order by convert(class_name using gbk);
  15. +----------+------------+-------------+
  16. | class_id | class_name | student_ids |
  17. +----------+------------+-------------+
  18. | 6 | asd | [6] |
  19. | 7 | qwe | [7] |
  20. | 8 | z | [8] |
  21. | 1 | | [1] |
  22. | 2 | | [2] |
  23. | 3 | | [3] |
  24. | 5 | | [5] |
  25. | 4 | | [4] |
  26. +----------+------------+-------------+

keywords

  1. convert_to