暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

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

原创 DBA小吉 2025-11-03
149

南大通用GBase 8s数据库中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() 函数的用法、特点及实际应用示例。如果在使用过程中遇到任何问题,欢迎随时在社区中提问,我们在这里为你提供支持!

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论