DB2 SQL 中的 IsNull 函数?
DB2 是否有与 isnull 函数相当的性能?
想象一下我们的一些产品是内部的,因此它们没有名称:
Select product.id, isnull(product.name, "Internal)
From product
可能会返回:
1 Socks
2 Shoes
3 Internal
4 Pants
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您需要使用 if/else,另一种选择是:
即:
Another option, in case you need to use if/else, is:
i.e.:
希望这可以帮助其他人
hope this might help someone else out there
我认为
COALESCE
函数部分类似于isnull
,但请尝试一下。为什么不通过应用程序使用空处理函数,这是更好的选择。
I think
COALESCE
function partially similar to theisnull
, but try it.Why don't you go for null handling functions through application programs, it is better alternative.
COALESCE
函数与ISNULL
函数相同笔记。 您必须使用
COALESCE
函数,该函数与您检查为空的列的数据类型相同。COALESCE
function sameISNULL
functionNote. you must use
COALESCE
function with same data type of column that you check is null.我对 DB2 不熟悉,但是你尝试过 COALESCE 吗?
IE:
I'm not familiar with DB2, but have you tried COALESCE?
ie:
DB2中有一个函数NVL(field, value if null)。
示例:
SELECT ID, NVL(NAME, "Internal) AS NAME, NVL(PRICE,0) AS PRICE FROM Product with UR;
In DB2 there is a function NVL(field, value if null).
Example:
SELECT ID, NVL(NAME, "Internal) AS NAME, NVL(PRICE,0) AS PRICE FROM PRODUCT WITH UR;
就其价值而言,COALESCE 很相似,但却
是您在 DB2 中寻找的完全匹配的对象。
COALESCE 允许多个参数,返回第一个 NON NULL 表达式,而 IFNULL 只允许表达式和默认值。
因此,为
您提供了您正在寻找的内容以及之前的答案,只是为了完整性而添加。
For what its worth, COALESCE is similiar but
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
Gives you what you're looking for as well as the previous answers, just adding for completeness.