counter customizable free hit

Thursday, July 28, 2005

Using IFNULL ( )

NVL() is a great function in Oracle to convert NULL columns into a more useable format, for example it's often the case on reports to convert NULL numeric columns to 0 for better readability.

In MySQL you can use IFNULL() in the same way.

mysql> select emp_id, salary, bonus from salary;
+--------+---------+-------+
| emp_id | salary | bonus |
+--------+---------+-------+
| 1 | 2000.00 | NULL |
+--------+---------+-------+
1 row in set (0.00 sec)

mysql> select emp_id, salary, ifnull(bonus,0) from salary;
+--------+---------+-----------------+
| emp_id | salary | ifnull(bonus,0) |
+--------+---------+-----------------+
| 1 | 2000.00 | 0.00 |
+--------+---------+-----------------+
1 row in set (0.00 sec)

0 Comments:

Post a Comment

<< Home