Skip to main content
Skip to main content

CONVERT_TO

convert_to​

description​

Syntax​

VARCHAR 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​

mysql> select * from class_test order by class_name;
+----------+------------+-------------+
| class_id | class_name | student_ids |
+----------+------------+-------------+
| 6 | asd | [6] |
| 7 | qwe | [7] |
| 8 | z | [8] |
| 2 | ε“ˆ | [2] |
| 3 | 哦 | [3] |
| 1 | ε•Š | [1] |
| 4 | εΌ  | [4] |
| 5 | ζˆ‘ | [5] |
+----------+------------+-------------+

mysql> select * from class_test order by convert(class_name using gbk);
+----------+------------+-------------+
| class_id | class_name | student_ids |
+----------+------------+-------------+
| 6 | asd | [6] |
| 7 | qwe | [7] |
| 8 | z | [8] |
| 1 | ε•Š | [1] |
| 2 | ε“ˆ | [2] |
| 3 | 哦 | [3] |
| 5 | ζˆ‘ | [5] |
| 4 | εΌ  | [4] |
+----------+------------+-------------+

keywords​

convert_to