Oracle
  Home arrow Oracle arrow Page 2 - Working with REF CURSOR in PL/SQL
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ORACLE

Working with REF CURSOR in PL/SQL
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 143
    2007-02-12

    Table of Contents:
  • Working with REF CURSOR in PL/SQL
  • Working with RECORD and REF CURSOR
  • Working with more than one query with the same REF CURSOR
  • Dealing with REF CURSOR in the sub-programs of a PL/SQL block

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with REF CURSOR in PL/SQL - Working with RECORD and REF CURSOR


    (Page 2 of 4 )

    Until now, we have been working either with %TYPE or %ROWTYPE. This means we are working with either one value or one complete record. How do we create our own data type, with our own specified number of values to hold? This is where TYPE and RECORD come in.  Let us consider the following example:

    declare
      type r_cursor is REF CURSOR;
      c_emp r_cursor;
      type rec_emp is record
      (
        name  varchar2(20),
        sal   number(6)
      );
      er rec_emp;
    begin
      open c_emp for select ename,sal from emp;
      loop
          fetch c_emp into er;
          exit when c_emp%notfound;
          dbms_output.put_line(er.name || ' - ' || er.sal);
      end loop;
      close c_emp;
    end;

    The most confusing aspect from the above program is the following:

      type rec_emp is record
      (
        name  varchar2(20),
        sal   number(6)
      );

    The above defines a new data type named "rec_emp" (just like %ROWTYPE with limited specified fields) which can hold two fields, namely "name" and "sal."

      er rec_emp;

    The above statement declares a variable "er" based on the datatype "rec_emp."  This means that "er" internally contains the fields "name" and "job."

          fetch c_emp into er;

    The above statement pulls out a row of information (in this case "ename" and "sal") and places the same into the fields "name" and "sal" of the variable "er."  Finally, I display both of those values using the following statement:

          dbms_output.put_line(er.name || ' - ' || er.sal);

    More Oracle Articles
    More By Jagadish Chatarji


       · This is a simple introduction to REF CURSOR in PL/SQL. Hope you will enjoy it. If...
       · dear sir, this article is very use full for the beginner like me.Thanks a...
       · It is very good article for the starters in PL/SQL
       · thanks!this was a great article for me and gave me new insights.
       · I would like to know how to handle data from a ref cursor to a record type when i...
       · I liked they way,all your topics are put in.This one was also very easy to...
       · This is really to good explanation with examples. I was able to understand it in a...
       · very good one
       · great way of explaining the concept
       · Its really a good way of explaining ina simple way..ThanksJeg
       · Thanks Jag for the enlightening article on Reference cursors...it was a lot more...
       · Thanks allot for providing us a very good description on Ref Cursors. I found this...
     

       

    ORACLE ARTICLES

    - Implementing and Using Oracle`s Restore Poin...
    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...
    - Sub-templates and More with Oracle HTML DB





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway