The purpose of VALUE function in DB2 is to check for NULL values and it can be used in place of NULL indicator or COALESCE function. The VALUE function replaces the column value with the given argument if it contains a NULL value.
For example, if we have an ORDER table and we have to extract ORDER_ID and ORDER_DESCRIPTION from this table. The ORDER_DECRIPTION column can have NULL values.
If this is the case, we have to replace ORDER_DESCRIPTION with SPACES, then we can use the below query:
EXEC SQL SELECT ORDER_ID, VALUE(ORDER_DESCRIPTION, ‘ ‘) INTO :ORDER-ID, :ORDER-DESCRIPTION FROM ORDERS END-EXEC
In this case, the VALUE function will take two arguments. The first one is the name of the column and second one is the expected value if the column contains NULL values.