I have a table where message is a varchar column type.
mysql> select * from todel;
+---------+
| message |
+---------+
| 73, 116 |
+---------+
1 row in set (0.00 sec)
I am not able to convert the ASCII values to string.
mysql> select char(message) from todel;
+---------------+
| char(message) |
+---------------+
| I |
+---------------+
1 row in set, 1 warning (0.01 sec)
mysql> show warnings;
+---------+------+----------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '73, 116' |
+---------+------+----------------------------------------------+
1 row in set (0.00 sec)
If I use char function directly, then it works as expected:
mysql> select char(73, 116);
+---------------+
| char(73, 116) |
+---------------+
| It |
+---------------+
1 row in set (0.00 sec)
How do I use the "char" function while selecting varchar data from a table?
You can use SUBSTRING_INDEX() to separate the two strings and then convert them with CHAR()
SELECT CHAR(SUBSTRING_INDEX('73, 116', ',', 1)) --I
SELECT CHAR(SUBSTRING_INDEX('73, 116', ',', -1)) --t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With