oracle用这么几个函数,可以帮助我们解决数据上null或0的处理
1、NVL()函数
1.1)介绍:NVL(expr1,expr2),若expr1为null, 返回expr2; 不为null,返回expr1。 注意:两者类型要一致
1.2)用法:
--expr1为空,返回expr2,结果:'未知'-- select NVL(null,'未知') SexType from dual; --expr1不为空,返回expr1, 结果:1 -- select NVL('1','2') SexType from dual;
1.3)实际应用:
如:我们查询表数据出现这种结果,某个字段若为null,返回0
--未加函数时情况 -- select A.UseFlag 使用标志,A.NAME 单据名称 from Dxc_Receive_Notice A
若字段不为null,直接返回字段本身
--加函数时情况,要求(field 为null,返回0 ;field 不为null,返回本身) -- select NVL(A.UseFlag,'0') 使用标志,A.NAME 单据名称 from Dxc_Receive_Notice A