Oracle
  Home arrow Oracle arrow Page 3 - Database Interaction with PL/SQL, part...
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, part 3
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 17
    2005-06-07

    Table of Contents:
  • Database Interaction with PL/SQL, part 3
  • Using TABLE Without Interacting With Database
  • Combining TABLE and RECORD
  • NESTED TABLES and PL/SQL
  • Using DML Commands on NESTED TABLES Within PL/SQL

  • 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
     
    IBM developerWorks
     
    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, part 3 - Combining TABLE and RECORD


    (Page 3 of 5 )

    In my previous article, I explained PL/SQL records. Now we shall combine RECORDs with TABLEs to achieve effective results in a simple way. Let us consider the following example.

     

    declare
       
    type t_empRec is record
       
    (
           
    ename emp.ename%type,
           
    sal emp.sal%type,
           
    deptno emp.deptno%type
       
    );
       
    type t_emptbl is table of t_emprec;
        v_emptbl    t_emptbl;
    begin
       
    select ename,sal,deptno BULK COLLECT into v_emptbl from emp;
       
    for i in v_emptbl.first .. v_emptbl.last
       
    loop
           
    dbms_output.put_line(v_emptbl(i).ename || ',' ||
             v_emptbl(i).sal || ',' || v_emptbl(i).deptno);
       
    end loop;
    end;

    The above program retrieves 'ename', 'sal' and 'deptno' columns from 'emp' table and displays all of those details. In my previous article, I displayed the same but used %ROWTYPE. Now in this program, I am combining the definitions of RECORD and TABLE to store only the data we need (but not the entire row). The most important statement in the above program is the following:

    type t_emptbl is table of t_emprec;

    That statement defines a PL/SQL table named 't_emptbl'. But the content (rows) within that table should match with the structure defined in the following declaration:

    type t_empRec is record
    (
       
    ename emp.ename%type,
       
    sal emp.sal%type,
       
    deptno emp.deptno%type
    );

    So, indirectly 't_emptbl' can have any number of rows with only the fields 'ename', 'sal' and 'deptno'. This is a wonderful technique to define PL/SQL tables with our own fields. The rest of the program is just similar to the example I gave in my previous article.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, this is my article on working with database information (several other...
       · Author mentions that subscript starts from 0. trying to access v_numtbl(0) results...
       · hi,I've gone through some of your articles.They are really an excellent for...
     

       

    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

    Click Here




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