How to count the no of records of a table without using
COUNT function?
Answers were Sorted based on User's Feedback
Answer / ajit
declare
cursor c1
is
select * from emp;
i c1%rowtype;
begin
open c1;
loop
fetch c1 into i ;
exit when c1%notfound;
end loop;
dbms_output.put_line(c1%rowcount);
close c1;
end;
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / senthil kumar
Hi Ramaprasad 'select max(rownum) from emp; ' this is passible
but
declare
cursor c1(dpno emp.deptno%type)is select * from emp where
deptno=dpno;
i c1%rowtype;
begin
open c1(dpno);
loop
fetch c1 into i ;
exit when c1%notfound;
dbms_output.put_line(c1%rowcount);
end loop;
close c1;
end;
this is NOT Passible , because this one just show all records Not count it.......
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / vikram
select col1,col2,1 as SNO,sum(sno) from emp
group by 1,2,3
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / suneelkumar
Hi guys..
rownum is virtual column we con't use max(rownum) i t will
give the error unknown colum...
so by using cursor we can count
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / ramaprasad
select rownum from emp;
select max(rownum) from emp;
declare
cursor c1(dpno emp.deptno%type)is select * from emp where
deptno=dpno;
i c1%rowtype;
begin
open c1(dpno);
loop
fetch c1 into i ;
exit when c1%notfound;
dbms_output.put_line(c1%rowcount);
end loop;
close c1;
end;
| Is This Answer Correct ? | 1 Yes | 4 No |
Answer / kart
using select command
select * from xxx; we will get the no of rows at bottom
if the feedback is unset
then use the plsql with cursor;
select rownum from table; the last value
is the number of records
| Is This Answer Correct ? | 4 Yes | 9 No |
What are pl sql data types?
What is Histogram?
Why do we create views in sql?
Explain two easy sql optimizations.
How to perform a loop through all tables in pl/sql?
What is the use of a view in sql?
what is the different between unique+not null & primary key,
how to check the 3rd max salary from an employee table?
wirte a query to filter improper date format follwing table? date 20-apr 22-may-2010 26-jun-2010 feb-2009 i want the output date 22-may-2010 26-jun-2010
what is self join and what is the requirement of self join? : Sql dba
Explain table and field in sql?
Initially question was asked to mention the types of indexes. Then asked about BITMAP INDEX and B-Tree Index
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)