Home arrow Oracle arrow Page 6 - Database Interaction with PL/SQL: Explict Cursors in Depth

Can we use JOINS in cursors? - Oracle

This is part 11 of a series of articles focusing on database interactions with Oracle PL/SQL. In my previous article, I introduced the concept of the explicit cursor and looked at several approaches for using the explicit cursors. In this article, we shall delve more deeply into explicit cursors.

TABLE OF CONTENTS:
  1. Database Interaction with PL/SQL: Explict Cursors in Depth
  2. Working with more than one cursor
  3. How the program works
  4. Further approaches to the above program
  5. Cursors with parameters – a complicated example
  6. Can we use JOINS in cursors?
By: Jagadish Chatarji
Rating: starstarstarstarstar / 25
August 02, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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;



 
 
>>> More Oracle Articles          >>> More By Jagadish Chatarji
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ORACLE ARTICLES

- Oracle Java Security Woes Continue
- Oracle's New IaaS Cloud Option: There's a Ca...
- Oracle Acquires Eloqua to Boost Cloud Presen...
- Choosing Innovation: Oracle Survey Insights
- Oracle Fixes Privilege Escalation Bug
- Oracle`s Communications Service Availability...
- Oracle Releases Exalytics, Taleo Plans
- Oracle Releases Communications Network Integ...
- Oracle Releases Communications Data Model 11...
- Oracle Releases PeopleSoft PeopleTools 8.52
- Oracle Integrates Cloudera Apache Distro, My...
- Oracle Releases MySQL 5.5.18
- Oracle Announces NoSQL Database Availability
- Sorting Database Columns With the SELECT Sta...
- Retrieving Table Data with the LIKE Operator

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: