如何查询某一行有几个空值?

Rick_ang 2010-11-11 11:14:35
RT,数据库中某一有多少个空值,这样的SQL语句如何写?
...全文
300 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rick_ang 2010-11-11
  • 打赏
  • 举报
回复
谢谢各位,用了nvl2,得到了结果了
lxyzxq2008 2010-11-11
  • 打赏
  • 举报
回复
把列转成行,然后再抽出!=null的
心中的彩虹 2010-11-11
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lnuwhy 的回复:]
还有一种select nvl(字段1,1,0)+....+nvl(字段n,1,0)
from table
where ....;
应该更好一点
[/Quote]
--他这是针对某个值里面含空值 不是整个列的值为空吧
select nvl2(字段1,0,1)+....+nvl2(字段n,0,1)
minitoy 2010-11-11
  • 打赏
  • 举报
回复
nvl没有这种用法的.你应该也是想用nvl2的.
SQL> select nvl(null,null,1) from dual;

select nvl(null,null,1) from dual

ORA-00909: invalid number of arguments

NVL2(expr1, expr2, expr3)
NVL2 lets you determine the value returned by a query based on whether a specified expression is null or not null. If expr1 is not null, then NVL2 returns expr2. If expr1 is null, then NVL2 returns expr3.
[Quote=引用 7 楼 lnuwhy 的回复:]
引用 5 楼 lnuwhy 的回复:
还有一种select nvl(字段1,1,0)+....+nvl(字段n,1,0)
from table
where ....;
应该更好一点

select nvl(字段1,0,1)+....+nvl(字段n,0,1)
from table
where ....;
在水一方太狠了。。。。
[/Quote]
心中的彩虹 2010-11-11
  • 打赏
  • 举报
回复
[Quote=引用楼主 rick_ang 的回复:]
RT,数据库中某一行有多少个空值,这样的SQL语句如何写?
[/Quote]

length(col)-length(replace(col,' ',''))+length(col2)-length(replace(co2l,' ',''))......
minitoy 2010-11-11
  • 打赏
  • 举报
回复
哈哈,这有个说法的,好像叫"漂亮的三连击"[Quote=引用 7 楼 lnuwhy 的回复:]
引用 5 楼 lnuwhy 的回复:
还有一种select nvl(字段1,1,0)+....+nvl(字段n,1,0)
from table
where ....;
应该更好一点

select nvl(字段1,0,1)+....+nvl(字段n,0,1)
from table
where ....;
在水一方太狠了。。。。
[/Quote]
lnuwhy 2010-11-11
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lnuwhy 的回复:]
还有一种select nvl(字段1,1,0)+....+nvl(字段n,1,0)
from table
where ....;
应该更好一点
[/Quote]
select nvl(字段1,0,1)+....+nvl(字段n,0,1)
from table
where ....;
在水一方太狠了。。。。
feixianxxx 2010-11-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 minitoy 的回复:]

SQL code
select decode(字段1,null,1,0)+....+decode(字段n,null,1,0) from table;
[/Quote]、
...
lnuwhy 2010-11-11
  • 打赏
  • 举报
回复
还有一种select nvl(字段1,1,0)+....+nvl(字段n,1,0)
from table
where ....;
应该更好一点
minitoy 2010-11-11
  • 打赏
  • 举报
回复
nvl2(字段,0,1)也是可以的.
minitoy 2010-11-11
  • 打赏
  • 举报
回复
select decode(字段1,null,1,0)+....+decode(字段n,null,1,0) 
from table
where ....;
minitoy 2010-11-11
  • 打赏
  • 举报
回复
select decode(字段1,null,1,0)+....+decode(字段n,null,1,0) from table;
Rick_ang 2010-11-11
  • 打赏
  • 举报
回复
说清楚一些:是某一行有多少列的数据为空,这样的SQL怎么写呢?ORACLE数据库

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧