Home » SQL & PL/SQL » SQL & PL/SQL » Rowcount in a SQL Query
Rowcount in a SQL Query [message #30815] Mon, 24 May 2004 05:52 Go to next message
Sunil Kumar Puli
Messages: 1
Registered: May 2004
Junior Member
In a SQL query, along with the field values, Can I find out how many rows (ROWCOUNT) that this query returned. This I should be able to find out, at the time of processing of the first record it self. Is there any way for this or not. 
Re: Rowcount in a SQL Query [message #30816 is a reply to message #30815] Mon, 24 May 2004 06:27 Go to previous message
Art Metzer
Messages: 2480
Registered: December 2002
Senior Member
Are you on at least Oracle version 9i? If so, you can use the COUNT analytic function within PL/SQL to find out:
SQL@9I> BEGIN
  2      FOR i IN (SELECT e.ename
  3                ,      e.job
  4                ,      e.sal
  5                ,      ROWNUM          ith
  6                ,      <font color=red>COUNT(*) OVER()</font> qty
  7                FROM   emp   e
  8                WHERE  e.ename LIKE '%A%') LOOP
  9          DBMS_OUTPUT.PUT_LINE(i.ename
 10                               || ' is record '
 11                               || TO_CHAR(i.ith)
 12                               || ' of '
 13                               || TO_CHAR(i.qty));
 14      END LOOP;
 15  END;
 16  /
ALLEN is record 1 of 7
WARD is record 2 of 7
MARTIN is record 3 of 7
BLAKE is record 4 of 7
CLARK is record 5 of 7
ADAMS is record 6 of 7
JAMES is record 7 of 7
 
PL/SQL procedure successfully completed.
 
SQL@9I>
HTH,

Art.
Previous Topic: Trigger
Next Topic: ORA-24344: success with compilation error
Goto Forum:
  


Current Time: Fri Oct 03 14:07:24 CDT 2025