How MySQL stored function evaluates if it got NULL value while using the dynamic values from a table?


In such kind of cases when a stored function got NULL values then it will return NULL as the result. It can be understood from the example below in which we have a NULL value in the records of student ‘Mohit’. Now, when we will apply the stored function ‘avg_marks’ on this data, it will return NULL as result.

mysql> Select * from Student_marks;
+-------+------+---------+---------+---------+
| Name  | Math | English | Science | History |
+-------+------+---------+---------+---------+
| Raman |   95 |      89 |      85 |      81 |
| Rahul |   90 |      87 |      86 |      81 |
| Mohit |   90 |    NULL |      86 |      81 |
+-------+------+---------+---------+---------+
3 rows in set (0.00 sec)

mysql> SELECT Avg_marks('Mohit') AS 'MOHIT_marks';
+-------------+
| MOHIT_marks |
+-------------+
|        NULL |
+-------------+
1 row in set (0.00 sec)

Updated on: 13-Feb-2020

152 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements