Skip to Main Content
  • Questions
  • How to count records without using count function

Breadcrumb

May 4th

Question and Answer

Connor McDonald

Thanks for the question, sidharth.

Asked: March 09, 2018 - 9:05 pm UTC

Last updated: March 14, 2018 - 6:25 am UTC

Version: 12c

Viewed 1000+ times

You Asked

Hi,

How we can find employee count department wise from emp table without using count function using a plsql block.

and Connor said...

Sounds like homework to me :-) So I'll give you some clues

option 1:
- use a cursor to loop through the records incrementing a counter variable with each fetch

option 2:
- gather table statistics
- then query num_rows from user_tables




Rating

  (3 ratings)

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

Comments

How do i start my car without a key? :-)

GJ, March 11, 2018 - 2:43 pm UTC


A reader, March 12, 2018 - 4:28 pm UTC

"How we can find employee count department wise from emp table without using count function"?

Why would you want or need to?
Connor McDonald
March 13, 2018 - 2:20 am UTC

When it says:

"Student Notebook: Question 7: How we can find employee count department wise from emp table without using count function"?

:-)

Count without using COUNT function

John Gasch, March 13, 2018 - 3:36 pm UTC

Option 3: For all practical purposes, SUM(1) is equivalent to COUNT(*), so it can be done just using a simple select statement. To satisfy the requirement of "using a plsql block", simply wrap the select statement inside a function. Keep it simple!

Connor McDonald
March 14, 2018 - 6:25 am UTC

Good point.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library