How can we produce a string, other than default binary string, in a given character set by MySQL CHAR() function?


We can use the keyword USING to produce a string, other than default binary string, in a given character set. Following result set will demonstrate it −

mysql> Select CHARSET(CHAR(85 USING utf8));
+------------------------------+
| CHARSET(CHAR(85 USING utf8)) |
+------------------------------+
| utf8                         |
+------------------------------+
1 row in set (0.00 sec)

The above result set shows that the returned binary string is utf8 because we write utf8 after the keyword USING.

mysql> Select CHARSET(CHAR(85 USING latin1));
+--------------------------------+
| CHARSET(CHAR(85 USING latin1)) |
+--------------------------------+
| latin1                         |
+--------------------------------+
1 row in set (0.00 sec)

The above result set shows that the returned binary string is latin1 because we write latin1 after the keyword USING.

Updated on: 22-Jun-2020

42 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements