Oracle
  Home arrow Oracle arrow Page 6 - Database Interaction with PL/SQL: Expl...
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

Database Interaction with PL/SQL: Explict Cursors in Depth
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 23
    2005-08-02

    Table of Contents:
  • Database Interaction with PL/SQL: Explict Cursors in Depth
  • Working with more than one cursor
  • How the program works
  • Further approaches to the above program
  • Cursors with parameters – a complicated example
  • Can we use JOINS in cursors?

  • 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


    Database Interaction with PL/SQL: Explict Cursors in Depth - Can we use JOINS in cursors?


    (Page 6 of 6 )

    Why not? We can use almost any type of query (including joins, sub-queries etc) with cursor declarations. If you have any expressions as columns, then you are required to provide an alias for each of them.  The following program is a demonstration:

    declare

      cursor c_emp is

            select ename,sal*12 as annsal,dname

            from emp,dept

            where emp.deptno = dept.deptno;

      r_emp c_emp%rowtype;

    begin

      open c_emp;

      loop

            fetch c_emp into r_emp;

            exit when c_emp%notfound;

            dbms_output.put_line(r_emp.ename || ' - ' || r_emp.annsal || ' - ' || r_emp.dname);

      end loop;

      close c_emp;

    end;

    In the above program, “sal*12” is an expression provided with an alias “annsal” (annual salary). The beauty of ‘r_emp’ is that it automatically contains ‘annsal’ as a member without having any declaration. And I provide the cursor FOR loop version for the above program as follows:

    declare

      cursor c_emp is

            select ename,sal*12 as annsal,dname

            from emp,dept

            where emp.deptno = dept.deptno;

    begin

      for r_emp in c_emp

      loop

            dbms_output.put_line(r_emp.ename || ' - ' || r_emp.annsal || ' - ' || r_emp.dname);

      end loop;

    end;


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys, this is my in-depth article on working with explicit cursors in PL/SQL....
       · Thank you very much for your in depth look at cursors. It helps me see what else can...
     

       

    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