Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, santhoshreddy.

Asked: April 21, 2017 - 2:28 pm UTC

Last updated: April 26, 2017 - 8:48 pm UTC

Version: 11G

Viewed 1000+ times

You Asked

Hi,

I created a table called Temp in that i inserted 2 NULL Rows so now total rows is 8.
INSERT INTO TEMP VALUES(NULL,NULL);
When i executed SELECT COUNT(*) FROM TEMP giving Result as 8 it also counted 2 NULL Rows as per my knowledge COUNT ignores NULL Rows but in this case it considered NULL Rows.

can you Explain how is it possible?

with LiveSQL Test Case:

and Chris said...

No. Count(<expression>) finds the number of non-null rows. Count(*) is always the total number of rows the query returns, regardless of null:

with rws as (
  select rownum x from dual union all
  select null x from dual
)
  select count(*), count(x) from rws;

COUNT(*)  COUNT(X)  
2         1  


I discuss this further in this video:


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

ROWID

A reader, April 26, 2017 - 5:29 am UTC

Does ROWID column get generated internally for every Table while Querying like ROWNUM?
Chris Saxon
April 26, 2017 - 8:48 pm UTC

Rowid is the physical location of the row for heap tables:

http://docs.oracle.com/database/122/SQLRF/ROWID-Pseudocolumn.htm#SQLRF00254

Index-organized tables have a logical rowid. This is an enconding of the table's primary key:

http://docs.oracle.com/database/122/CNCPT/indexes-and-index-organized-tables.htm#CNCPT912