Home » SQL & PL/SQL » SQL & PL/SQL » count function
count function [message #223197] Wed, 07 March 2007 23:54 Go to next message
subramanian.sp
Messages: 13
Registered: March 2007
Location: Pune
Junior Member
1) select count(1) from emp where empcode=5454353 group by firstname;

if where condition fails , it goes to no_data_found exception but if i remove the
group by statement the result becomes 0. why ?


2) whats the difference between select count(1) and count(*) ?
Re: count function [message #223204 is a reply to message #223197] Thu, 08 March 2007 00:19 Go to previous messageGo to next message
caliguardo
Messages: 107
Registered: February 2007
Location: Chennai
Senior Member

OFFCOURSE...SINCE THERE IS NO DATA OUT THERE IT THROWS A NO_DATA_FOUND_EXCEPTION...LOL....


I don't think there is any major difference between Count(*) and count(1)..the only difference being the value inside brackets..
Re: count function [message #223206 is a reply to message #223197] Thu, 08 March 2007 00:27 Go to previous messageGo to next message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
1) furthermore when you remove the condition you may get more than one row with the group by clause! that's the way GROUP BY clause works. See some examples in documentation.
Check the result of
select firstname, count(1) from emp group by firstname;

2) Read about it on AskTom.
Re: count function [message #223253 is a reply to message #223206] Thu, 08 March 2007 03:17 Go to previous message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
reported

By: subramanian.sp
On: Thu, 08 March 2007 10:06
Reason: select count(*) from tablename will take more time to execute,but if you use select count(1) from tablename , system will take less time. even you can execute like select count(4356435) from tablename. How oracle is taking the argument function in c
I'm afraid you have a bit of an off day, subramanian.sp, because not only is your reply wrong (count(*) won't take more time than count(1)), you also failed to reply properly. Don't use the "report" link, use the "reply" button instead.

MHE
Previous Topic: How will we ensure LUW is working correct in PRAGMA AUTONOMOUS_TRANSACTION function.
Next Topic: Urgent Help required on Oracle Date Formats
Goto Forum:
  


Current Time: Sat Dec 10 05:00:26 CST 2016

Total time taken to generate the page: 0.15390 seconds