Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

select count(distinct(c_num)), Count(Unique(c_num)) gives wrong count

User_3YG1KMar 7 2022

Hi ,
I am new to this Oracle discussion community. Thanks in advance for team / every one who help us in giving solutions.
My question is
I created table c_1
Create Table c_1 (c_num Number );
Insert Into c_1 Values(1);
Insert Into c_1 Values(2);
Insert Into c_1 Values(2);
Insert Into c_1 Values(3);
Insert Into c_1 Values(3);
Insert Into c_1 Values(Null);
Insert Into c_1 Values(Null);
Commit;
Select Count(*) From c_1; ---- count - 8
Select Count(1) From c_1; ---- count - 8

Select Distinct(c_num) From c_1; ---- rows - 4
Select Unique(c_num) From c_1; ---- rows - 4

Select Count(Distinct(c_num)) From c_1; ---- count - 3
Select Count(Unique(c_num)) From c_1; --- count - 3
now , iam checking the Count(Distinct(c_num)) gives row count as 3 where as the number of rows in the table when i query Select Distinct(c_num) From c_1 are 4 . the last row is NULL, in the
Count(Distinct(c_num)) , the null value row is not getting counted and both Count(Distinct(c_num)) and Count(Unique(c_num)) gives count as 3 but not 4.
how this could happen

This post has been answered by Paulzip on Mar 7 2022
Jump to Answer
Comments
Post Details
Added on Mar 7 2022
8 comments
1,230 views