What MySQL returns if the first argument of INTERVAL() function is NULL?


MySQL returns -1 as output if the first argument of INTERVAL() function is NULL. Following example will demonstrate it −

mysql> Select INTERVAL(NULL,20,32,38,40,50,55);
+--------------------------------------+
| INTERVAL(NULL,20,32,38,40,50,55)     |
+--------------------------------------+
| -1                                   |
+--------------------------------------+
1 row in set (0.00 sec)

It will return -1 even if any of the other arguments is NULL along with the first argument.

mysql> Select INTERVAL(NULL,20,32,NULL,40,50,NULL);
+--------------------------------------+
| INTERVAL(NULL,20,32,NULL,40,50,NULL) |
+--------------------------------------+
| -1                                   |
+--------------------------------------+
1 row in set (0.00 sec)

If the first argument is not NULL and any one or more of the other argument is NULL, it will return the index value of greater number (if any).

mysql> Select INTERVAL(50,20,NULL,55,40,50,NULL);
+------------------------------------+
| INTERVAL(50,20,NULL,55,40,50,NULL) |
+------------------------------------+
| 2                                  |
+------------------------------------+
1 row in set (0.00 sec)

Advertisements