Handle null values in MySQL Query
- Jagadish. M
The following examples facilitate in handling null values in MySQL query itself instead of handling them in jsp pages.
Syntax:
Select IFNULL (exp1,exp2) , IFNULL (exp1,exp2) from tableName
IFNULL return exp1 if it is not null
Else
If exp1 is null then returns exp2
In Interface it looks like this:
Select IFNULL(Name,’ Not Available ’),IFNULL(Address,’Not Available ’),IFNULL(emailed,’Not Available’) from tableName
Result:
In Interface it looks like this:
Example 2:
Select IFNULL(Name,’ ’),IFNULL(Address,’ ’),IFNULL(emailed,’ ’) from tableName
Result:
(The author, Jagadish.M, is a Software Engineer at Binary Spectrum).