Home > Ask the Oracle Experts > Questions & Answers
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Returning number of rows to a REF CURSOR

Jason Law EXPERT RESPONSE FROM: Jason Law

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 19 February 2002
I was wondering if it is possible to get the number of rows returned to a REF CURSOR.

>
EXPERT RESPONSE

I believe Oracle is the only major database which uses the REF CURSOR type, so I will assume you are using Oracle. REF CURSORS are used in PL/SQL, Oracles procedural language, so I'll give you an example in a snippet of PL/SQL code.

Cursors in Oracle have attributes, such as %FOUND, %NOTFOUND, %ISOPEN, and %ROWCOUNT. When appended to the name of the cursor, they return useful information about its execution. %ROWCOUNT is the attribute that will give you the information you're looking for. Here is an example:

declare
  type tWeakCursor is REF CURSOR;
  cMyCursor tWeakCursor;
  vTable_Name varchar2(30);
begin
  open cMyCursor for 'select * from user_tables';
  loop
    fetch cMyCursor into vTable_Name;
    exit when cMyCursor%notfound;
    dbms_output.put_line( to_char(cMyCursor%rowcount) || 
                          ') ' || vTable_Name );
  end loop;
  close cMyCursor;
end;  
The %ROWCOUNT attribute returns the current row count of the cursor. After the cursor is opened, %ROWCOUNT is equal to zero. After every successful FETCH, ROWCOUNT is incremented by one.

For More Information

  • What do you think about this answer? E-mail the edtiors at editor@searchDatabase.com with your feedback.
  • The Best SQL Web Links: tips, tutorials, scripts, and more.
  • Have an SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
  • Ask your technical SQL questions -- or help out your peers by answering them -- in our live discussion forums.
  • Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts