What is the reverse function of CHAR() in MySQL

MySQLMySQLi Database

The reverse function of CHAR() is ASCII() or ORD() in MySQL. Here, ASCII() returns numeric value of left-most character, whereas ORD() return character code for the leftmost character of the argument

Let us first create a table −

mysql> create table DemoTable
(
   Value int,
   Value1 char(1),
   Value2 char(1)
);
Query OK, 0 rows affected (0.80 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(65,'A','A');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values(97,'a','a');
Query OK, 1 row affected (0.13 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-------+--------+--------+
| Value | Value1 | Value2 |
+-------+--------+--------+
|    65 |      A |      A |
|    97 |      a |      a |
+-------+--------+--------+
2 rows in set (0.00 sec)

Let us now implement the ASCII and ORD −

mysql> select char(Value),ASCII(Value1),ORD(Value2) from DemoTable;

This will produce the following output −

+-------------+---------------+-------------+
| char(Value) | ASCII(Value1) | ORD(Value2) |
+-------------+---------------+-------------+
| A           |            65 |          65 |
| a           |            97 |          97 |
+-------------+---------------+-------------+
2 rows in set (0.03 sec)
raja
Updated on 24-Sep-2019 14:06:35

Advertisements