Click here to Skip to main content
15,902,846 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We call PL/SQL stored procedures from Java code to process Oracle 10g database. When we need to retrieve some data, we use SYS_REFCURSOR OUT parameter. The question is: how we can get number of records in the cursor without duplicated SELECT?
(The %ROWCOUNT cursor attribute does not return the total number of rows for a query prior to the first fetch. If we fetch in stored procedure, we lose data.)
We use the following:
SQL
CREATE OR REPLACE PROCEDURE GET_DATA(p_cursor OUT SYS_REFCURSOR,
                                     nRecs    OUT INTEGER)
IS
BEGIN
OPEN p_cursor FOR SELECT * FROM SOME_TABLE WHERE ...;
SELECT COUNT(0) INTO nRecs FROM SOME_TABLE WHERE ...;
...
END GET_DATA;

So can we avoid the second SELECT to return number of records? Or may be we can somehow get it from SYS_REFCURSOR in Java?
Posted
Updated 14-Jul-10 2:27am
v2

1 solution

A quick google and the answer is here in 24.8.11. Example Using REF CURSOR in Java[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900