Oracle
  Home arrow Oracle arrow Database Interaction with PL/SQL: Nested Tables
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
ORACLE

Database Interaction with PL/SQL: Nested Tables
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 46
    2005-06-21


    Table of Contents:
  • Database Interaction with PL/SQL: Nested Tables
  • Working with DML statements using NESTED TABLE with OBJECT TYPE
  • Working with PL/SQL using NESTED TABLE with OBJECT TYPE
  • A Powerful FOR loop in PL/SQL

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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: Nested Tables
    ( Page 1 of 4 )

    This series has been focusing on database interactions with Oracle PL/SQL. Having just covered OBJECT TYPE in Oracle and both SQL and PL/SQL ways of working with OBJECTs in the last article, we will now learn about using NESTED TABLE with OBJECT TYPES from both SQL and PL/SQL point of views. We will also discuss FOR loops with an inline SELECT statement. This article is the fifth in this series.

    Please note that all the examples in this series have been tested only with Oracle 10g.  I didn’t really test them with all the previous versions of Oracle.  I suggest you to refer the documentation of respective version you are using, if any of the programs failed to execute.

    NESTED TABLE with OBJECT TYPE

    Part-3 of my series covered NESTED TABLE a bit and part-4 introduced the concept of OBJECT TYPE.  Now, we shall combine those two in this article.  Let us prepare scripts from scratch to discuss them in detail.  Consider the following:

    CREATE TYPE t_experience AS OBJECT
    (
        CompanyName    varchar2(20),
        Position       varchar2(20),
        NoOfYears      number(2)
    );
    /

    The above script just creates an OBJECT TYPE (which is almost similar to the one present in part-4). 

    CREATE TYPE t_experience_tbl AS TABLE OF t_experience;

    If we observe the above carefully, we are still creating another TYPE (not a concrete table), but it is of TABLE TYPE within database.  For our convenience, I named it as ‘t_experience_tbl’.

    CREATE TABLE employees
    (
        Name            varchar2(20),
       
    Experiences     t_experience_tbl
    )
    NESTED TABLE Experiences STORE AS Experiences_tab;

    The above statement creates a new table ‘employees’ (make sure to drop an old one if it exists) with only two fields,  ‘name’ and ‘experiences’.  The field ‘Experiences’ is created based on the TABLE TYPE ‘t_experience_tbl’.  This means that every employee can now store his experience list in the same row.  Indirectly, experience list itself is a table of information (CompanyName, Position, NoOfYears).  This table is being stored as a part of single row in the table ‘employees’, which is what the NESTED TABLE is.

    Even though the NESTED TABLE is logically part of the ‘employees’ table, it is stored externally (with a different table name ‘experiences_tab’) from the main table.  The following statement inserts a row into that table.

    insert into employees values
    (
        'jag',
        t_experience_tbl
        (
            t_experience('abc company','Software Engineer',3),
            t_experience('xyz company','System Analyst',2),
            t_experience('mnp company','Research fellow',4)
         )
    );

    Better not confuse ourselves with the example above.  ‘t_experience_tbl’ is a TABLE TYPE based on ‘t_experience’ OBJECT TYPE.  So, ‘t_experience_tbl’ can have any number of OBJECTs of TYPE ‘t_experience’.  The same concept is practiced above.  And you can insert any number of experiences for a single row.



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

       

    ORACLE ARTICLES

    - Oracle's Turn to Play in the Sun
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek