Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Tess.

Asked: September 26, 2000 - 4:23 pm UTC

Last updated: November 12, 2002 - 4:14 pm UTC

Version: 8.1.6

Viewed 1000+ times

You Asked

Hi Tom,

I'm trying to get the count of rows put into the ref cursor before the ref cursor is passed back to an ADO record set. I know that If i fetch out of the ref cursor I can use the cursor%ROWCOUNT. But this empties the ref cursor and I can not pass it back. I tried using a function on one of the fields and incrementing a global variable. On the first exec the global variable is zero and the records returned in the ref cursor totaled 2. The next exec the global variable goes to 2 and the records returned in the ref cursor totaled 2. The next exec the global variable was 4. I did not look at the ref cursor cause I knew it had 2 records. The next exec the global variable was still 4 I looked in the ref cursor, 2 records. Next exec the global variable went up to 6. It looks like the global variable only gets incremented when I look at the record set. So does that mean that the select is not executed until the ref cursor is looked at? I thought that the select was executed at the time the procedure was invoked and the information was placed into a memory location and the ref cursor returned the memory address to that location... So I'm confused about how the Ref cursor works and how to count tht number of records in it... Any suggestions?

Thanks!
Tess Goodwin


and Tom said...

You cannot get what we do not know.

Lets say you open a cursor like:

open X for select * from a_one_billion_row_table;

At the point in time you open that query -- we have absolutely NO IDEA how many rows it will retrieve. We do not prebuild the answer somewhere and then start handing them out. In most cases, we've just come up with a PLAN to get the rows -- we haven't gotten them.

SQL%RowCount is a count of the rows affected SO FAR. As you fetch we would increment that count. A ref cursor is no different then any other cursor -- it is not answered until right after you fetch the very last row from it.


Sorry but what you are after just isn't possible to get.

Rating

  (1 rating)

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

Comments

done it

A reader, November 12, 2002 - 4:14 pm UTC

Hi tom,

I found the solution.. so please don't spend your time
on that

Thanks,

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