Number of rows in Oracle SQL Select? Number of rows in Oracle SQL Select? oracle oracle

Number of rows in Oracle SQL Select?


Is there a way to do:

SELECT * FROM MY_ITEMS 

and then find out how many records are in there?

If you want it to be in this exact order, you can fetch all records on the client and count their number (almost all client libraries provide a function for that).

You can also do:

SELECT  i.*, COUNT(*) OVER ()FROM    my_items i

, which will return you the count along with each record.


If you're working in PL/SQL, you can use the SQL%ROWCOUNT pseudo-variable to get the number of rows affected by the last SQL statement. Might save you some effort.


This ought to do the trick.

WITH base AS(    SELECT *    FROM MY_ITEMS)SELECT (SELECT COUNT(*) FROM base) kount,       base.*FROM base