【www.gdgbn.com--Mssql】

sql isnull (oracle,mysql教程,mssql)

isnull
使用指定的替换值替换 null。

语法
isnull ( check_expression , replacement_value )

参数
check_expression

将被检查是否为 null的表达式。check_expression 可以是任何类型的。

replacement_value

在 check_expression 为 null时将返回的表达式。replacement_value 必须与

check_expresssion 具有相同的类型。

返回类型
返回与 check_expression 相同的类型。

注释
如果 check_expression 不为 null,那么返回该表达式的值;否则返回

replacement_value

示例
a. 将 isnull 与 avg 一起使用
下面的示例查找所有书的平均价格,用值 $10.00 替换 titles 表的 price 列中的

所有 null 条目。

use pubs
go
select avg(isnull(price, $10.00))
from titles
go

下面看一下其它数据库教程

oracle
oracle 没有 isnull() 函数。不过,我们可以使用 nvl() 函数达到相同的结果:

select productname,unitprice*(unitsinstock+nvl(unitsonorder,0))
from products
mysql
mysql 也拥有类似 isnull() 的函数。不过它的工作方式与微软的 isnull() 函数

有点不同。

在 mysql 中,我们可以使用 ifnull() 函数,就像这样:

select productname,unitprice*(unitsinstock+ifnull(unitsonorder,0))
from products

本文来源:http://www.gdgbn.com/shujuku/28781/