Oracle/PLSQL: Coalesce Function

本文介绍了Oracle/PL/SQL中的coalesce函数,它用于返回第一个非空表达式的值。通过实例展示了如何在SQL语句中使用此函数,相当于条件语句的简化。掌握这个函数有助于处理数据库查询中的空值问题。
摘要由CSDN通过智能技术生成

In Oracle/PLSQL, the coalesce function returns the first non-null expression in the list. If all expressions evaluate to null, then the coalesce function will return null.

Syntax

The syntax for the coalesce function is:

coalesce( expr1, expr2, ... expr_n )

expr1 to expr_n are the expressions to test for non-null values.

Applies To

  • Oracle 11g, Oracle 10g, Oracle 9i

For Example

You could use the coalesce function in an SQL statement as follows:

SELECT coalesce( address1, address2, address3 ) result

FROM suppliers;

The above coalesce statement is equivalent to the following IF-THEN-ELSE statement:

IF address1 is not null THEN

   result := address1;

ELSIF address2 is not null THEN

   result := address2;

ELSIF address3 is not null THEN

   result := address3;

ELSE

   result := null;

END IF;

The coalesce function will compare each value, one by one.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值