DB2 SQL 中的 IsNull 函数? [英] IsNull function in DB2 SQL?

查看:24
本文介绍了DB2 SQL 中的 IsNull 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有与 DB2 的 isnull 函数等效的性能?

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

可能会返回:

1 Socks 
2 Shoes 
3 Internal 
4 Pants

推荐答案

COALESCE 是一样的,但是

For what its worth, COALESCE is similiar but

IFNULL(expr1, default)

是您在 DB2 中寻找的完全匹配.

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

COALESCE 允许多个参数,返回第一个 NON NULL 表达式,而 IFNULL 只允许表达式和默认值.

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

这样

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.

这篇关于DB2 SQL 中的 IsNull 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆