SunQuest
 
       Oracle
  Home arrow Oracle arrow Page 3 - Database Interaction with PL/SQL, RECO...
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 
Actuate Whitepapers 
VeriSign Whitepapers 
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, RECORD and TABLE in Sub-programs
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 17
    2005-08-23

    Table of Contents:
  • Database Interaction with PL/SQL, RECORD and TABLE in Sub-programs
  • Mixing PROCEDURE and FUNCTION
  • Using RECORD with sub-programs
  • Returning a RECORD from FUNCTION
  • Working with PL/SQL TABLE and sub-programs

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Database Interaction with PL/SQL, RECORD and TABLE in Sub-programs - Using RECORD with sub-programs


    (Page 3 of 5 )

    In part two, I introduced the concept of RECORD. Now I would like to use RECORD together with sub-programs. Let us start with an example:

    declare

    TYPE t_emprec IS RECORD

    (

    name emp.ename%type,

    salary emp.sal%type,

    job emp.job%type

    );

    CURSOR c_emp is

    select ename,sal,job from emp;

    r_emp t_emprec;

    procedure dispEmp(v_emprec t_emprec) is

    begin

    dbms_output.put_line ('Name : ' || v_emprec.name);

    dbms_output.put_line ('Salary : ' || v_emprec.salary);

    dbms_output.put_line ('Job : ' || v_emprec.job);

    dbms_output.put_line ('-----------------------');

    end;

    begin

    for r_emp in c_emp

    loop

    dispEmp(r_emp);

    end loop;

    end;

    Let me explain this program part by part. The first part could be:

    TYPE t_emprec IS RECORD

    (

    name emp.ename%type,

    salary emp.sal%type,

    job emp.job%type

    );

    The above defines a new data type named ‘t_emprec’ (just like %ROWTYPE with limited specified fields) which can hold three fields, namely ‘name’, `salary’ and ‘job’.

    CURSOR c_emp is

    select ename,sal,job from emp;

    The above statement defined a cursor ‘c_emp’ based on SELECT statement provided.

    r_emp t_emprec;

    The above statement declares a variable ‘r_emp’ based on the datatype ‘t_emprec’. This means ‘r_emp’ internally contains the fields ‘name’, `salary’ and ‘job’. All the above declarations are available at the main program level. So, according to logic, we can use them throughout our program (including sub-programs).

    procedure dispEmp(v_emprec t_emprec) is

    begin

    dbms_output.put_line ('Name : ' || v_emprec.name);

    dbms_output.put_line ('Salary : ' || v_emprec.salary);

    dbms_output.put_line ('Job : ' || v_emprec.job);

    dbms_output.put_line ('-----------------------');

    end;

    The above is a procedure named ‘dispEmp’ which accepts a RECORD of type ‘t_emprec’ as a parameter and displays all the values available within the variable ‘v_emprec’ (of type ‘t_emprec’).

    for r_emp in c_emp

    loop

    dispEmp(r_emp);

    end loop;

    By using the above loop, we iterate through all employees. For each iteration, we are sending the information to procedure ‘dispEmp’ (as a parameter value) to get them displayed on the screen.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, this is my article on working with RECORD and TABLE in PL/SQL. You can...
     

       

    ORACLE ARTICLES

    - 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
    - Focusing on Templates in Oracle HTML DB





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