Select COUNT(*) and COUNT(column) are different things!
2014-11-03 16:01
381 查看
Select COUNT(*) and COUNT(column) are different things!
byTanel PoderPosted onAugust
21, 2009
Every now and then I see someone wondering why Oracle is “returning wrong results” for some count queries when counting using COUNT(column_name) instead of COUNT(*) or COUNT(<constant>).
Oracle is actually returning correct results, its just that sometimes the people asking the questions haven’t realized that COUNT(column) is something semantically different from COUNT(*).
COUNT(*) operation countsall rows fed to it by execution plan branch under it.
[b][b][b]COUNT(*) operation[/b][/b]统计表对应的段中所有的数据行(包括其上各列的值为空值null的数据行)
[/b]
COUNT(column) operation on the other handcountsall
non-null values in that column from rows fed to it by execution plan branch under it.
[b][b][b][b][b][b][b][b][b]COUNT(column)[/b][/b]
operation[/b][/b][/b]统计表对应的段中[b][b][b][b][b]其列上的值不为空值null的数据行[/b][/b][/b][/b]。[/b][/b][/b][/b]
[/b]
注释:[b]COUNT(column)的一般形式为COUNT(column1||[b][b]column2||......[/b])。[/b][/b]
And here’s a little example:
SQL> select count(*) from v$session; COUNT(*) ---------- 23 SQL> select count(username) from v$session; COUNT(USERNAME) --------------- 1 <<-- only one non-null value in that column SQL> select count(nvl(username,'blah')) from v$session; <<-- lets replace NULLs with non-nulls COUNT(NVL(USERNAME,'BLAH')) --------------------------- 23 参考: oracle count 0 谷歌
相关文章推荐
- Item 12. 赋值和初始化(Assignment and Initialization Are Different)
- Item 12. 赋值和初始化(Assignment and Initialization Are Different)
- mysql创建视图报错[Err] 1353 - View's SELECT and view's field list have different column counts
- redirect:2>&1使用&redirect and output and return value are different
- Select Count (*)和Select Count(1)以及Select Count(column)的区别
- Item 12. 赋值和初始化(Assignment and Initialization Are Different)
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes
- About Adultism and why things ar the way they are
- Error Code: 1175.You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.
- mysql update 报 You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode
- What Are Different Types Of Internal Tables and Their Usage
- MySQL错误:Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL easonjim
- Use data define file and colmap to map different column
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes
- 11i and R12 Table Count in Different Module
- 21.重载与重写(Overloading and Overriding Are Different)
- ORA-12537 if Listener (including SCAN Listener) and Database are Owned by Different OS User [ID 1069
- SSRS Report display both count and percent above chart bar column
- String object and String literal are different