IsNull function in DB2 SQL?

2019-02-11 20:46发布

Is there a performant equivalent to the isnull function for DB2?

Imagine some of our products are internal, so they don't have names:

Select product.id, isnull(product.name, "Internal) 
From product

Might return:

1 Socks 
2 Shoes 
3 Internal 
4 Pants

标签: sql null db2
7条回答
孤傲高冷的网名
2楼-- · 2019-02-11 20:54
Select Product.ID, VALUE(product.Name, "Internal") AS ProductName from Product
查看更多
看我几分像从前
3楼-- · 2019-02-11 20:55

I think COALESCE function partially similar to the isnull, but try it.

Why don't you go for null handling functions through application programs, it is better alternative.

查看更多
不美不萌又怎样
4楼-- · 2019-02-11 20:55

COALESCE function same ISNULL function Note. you must use COALESCE function with same data type of column that you check is null.

查看更多
走好不送
5楼-- · 2019-02-11 20:57

For what its worth, COALESCE is similiar but

IFNULL(expr1, default)

is the exact match you're looking for in DB2.

COALESCE allows multiple arguments, returning the first NON NULL expression, whereas IFNULL only permits the expression and the default.

Thus

SELECT product.ID, IFNULL(product.Name, "Internal") AS ProductName
FROM Product

Gives you what you're looking for as well as the previous answers, just adding for completeness.

查看更多
Root(大扎)
6楼-- · 2019-02-11 21:00

hope this might help someone else out there

  SELECT 
.... FROM XXX XX
WHERE
....
AND(
       param1 IS NULL
       OR XX.param1 = param1
       )
查看更多
7楼-- · 2019-02-11 21:10

I'm not familiar with DB2, but have you tried COALESCE?

ie:


SELECT Product.ID, COALESCE(product.Name, "Internal") AS ProductName
FROM Product
查看更多
登录 后发表回答