What would be the default return type of MySQL IFNULL() control flow operator?


Actually, the default return type of IFNULL(expression1, expression2) is more general of the two expressions, in the order STRING, REAL or INTEGER. It can be understood from the following example −

Example

mysql> Create table testing Select IFNULL(100,'testing123');
Query OK, 1 row affected (0.18 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> Select * from testing568;
+-----------------------+
| IFNULL(100,'testing') |
+-----------------------+
| 100                   |
+-----------------------+
1 row in set (0.00 sec)

mysql> Describe testing568;
+-----------------------+------------+------+-----+---------+-------+
| Field                 | Type       | Null | Key | Default | Extra |
+-----------------------+------------+------+-----+---------+-------+
| IFNULL(100,'testing') | varchar(7) | NO   |     |         |       |
+-----------------------+------------+------+-----+---------+-------+
1 row in set (0.03 sec)

From the above result set it is clear that in this case, the type of the column is varchar(7). In other words, it is of string type.

Updated on: 22-Jun-2020

53 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements