zoukankan      html  css  js  c++  java
  • oracle中count(列名)不计算空值

    测试一count(列名)是否计算空值
    --建个测试表
    carete table test(id number10),note varcahr2(10));
    --插入数据
    insert into test(id,note) values (1,'1');--note列有值
    
    insert into test(id,note) values (2,'');--note有个''
    
    insert into test(id) values (3);--note为空值
    
    commite;
    
    --使用count(*/常量)
    select count(*) from test;
    
      COUNT(*)
    ----------
             3
    
    select count(1) from test;
    
      COUNT(1)
    ----------
             3
    
    --使用count(列名)
    select count(id) from test;
    
      COUNT(id)--这里是改上面的所以id是小写的,默认应该是count(ID)
    ----------
             3
    
    select count(note) from test;
    
     COUNT(NOTE)
    ----------
             1
    
    结论:count(列名)不计算空值的列
    
    测试二--是否根据rowid来计算
    rowid是物理地址,union all单表
    select count(id) from (select rowid rid,id from test union all
        select rowid rid,id from test);
    
    COUNT(ID)
    ----------
             6
    显然不是rowid来计算的,rowid是相当于一个列;相比较rowid更可能和count()结果一致的应该是rownum,rownum序列的最终值应该是count的结果;
    
    结论:count不是依据rowid计算的
  • 相关阅读:
    算法时间测试
    HDU1164
    git 中 HEAD detached from 802e836
    mysql中的substring()截取字符函数
    git分支/标签操作
    git简介、基本命令和仓库操作
    markdown编辑器学习
    数据库的三范式
    switch语句能否作用在byte,long,string上
    Spring的优缺点
  • 原文地址:https://www.cnblogs.com/Babylon/p/7717808.html
Copyright © 2011-2022 走看看