MySQL

Handle 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

Example 1:

NameAddressemailID
JagadishBangalorenull


In Interface it looks like this:



Select IFNULL(Name,’ Not Available ’),IFNULL(Address,’Not Available ’),IFNULL(emailed,’Not Available’) from tableName

Result:

Telephone1 Telephone2Fax
9903124243Not AvailableNot Available


In Interface it looks like this:




Example 2:

Select IFNULL(Name,’ ’),IFNULL(Address,’ ’),IFNULL(emailed,’ ’) from tableName

Result:

Telephoen1Telephone2Fax
9903124243


In Interface it looks like this:

Comments