南大通用GBase 8s中的 ISNULL() 函数的介绍

65 阅读2分钟

原文链接:www.gbase.cn/community/p…
更多精彩内容尽在南大通用GBase技术社区,南大通用致力于成为用户最信赖的数据库产品供应商。

 ISNULL() 函数的介绍

ISNULL()   函数用于处理   NULL   值。它接受一个或两个参数,并根据参数的不同返回相应的值。

具体来说:

• 双参形式:  ISNULL(a, b)  ,如果   a   不为   NULL  ,则返回   a  ;如果   a   为   NULL  ,则返回   b  。

• 单参形式:  ISNULL(a)  ,如果   a   为   NULL  ,则返回布尔值   t  ;否则返回   f  。

 ISNULL() 函数的特点

双参形式:

• 返回从左边第一个不为   NULL   的值。

• 如果两个参数都为   NULL  ,则返回空。

 单参形式:

• 返回布尔值   t   或   f  。

• 如果参数为   NULL  ,返回   t  ;否则返回   f 。

• 可以与   VARCHAR   等字符类型转换。

示例

示例1: ISNULL() 双参函数:

--预期结果:12
select isnull(12,null) from dual;
--预期结果:aa
select isnull(null,’aa’) from dual;
--预期结果:
select isnull(null,null) from dual;
--预期结果:abc
select isnull(isnull(‘abc’,null),’ef’) from dual;

示例2: ISNULL() 单参函数:

--预期结果:f
select isnull(‘aa’) from dual;
--预期结果: t
select isnull(null) from dual;
--预期结果:f
select isnull(‘null’) from dual;
drop table if exists t1;
create table t1(
id int,
col1 int,
col2 int
);
insert into t1 values(1,1,1);
insert into t1 values(2,null,null);
insert into t1 values(3,4,4);
insert into t1 values(4,0,0);
select * from t1;
--预期结果:
--id  col1   null_col2
--2   null      1
with tmp1 as(
  select id,col1,isnull(col1),sum(col2) as total_col2
  from t1
  group by id,col1
),
tmp2 as(
  select id,col1,isnull(tmp1.total_col2) as null_col2
  from tmp1
  where id>1 and isnull(col1)=’t’
)
select dt.id,dt.col1,dt.null_col2 from tmp2 dt;

通过本文的介绍,可以解了 GBase 8s 中   ISNULL()   函数的用法、特点及实际应用示例。如果在使用过程中遇到任何问题,欢迎随时在社区中提问,我们在这里为你提供支持!

原文链接:www.gbase.cn/community/p…
更多精彩内容尽在南大通用GBase技术社区,南大通用致力于成为用户最信赖的数据库产品供应商。