摘要:预期结果:12select isnull(12,null) from dual; --预期结果:aa select isnull(null,’aa’) from dual; --预期结果: select isnull(null,null) from dual;
南大通用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 双参函数:
--预期结果:12select 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 1with 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 函数的用法、特点及实际应用示例。如果在使用过程中遇到任何问题,欢迎随时在社区中提问,我们在这里为你提供支持!
来源:GBASE南大通用