Oracle
  Home arrow Oracle arrow Page 2 - Database Interaction with PL/SQL: Nest...
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: Nested Tables
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 35
    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:
      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

    Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!

    Database Interaction with PL/SQL: Nested Tables - Working with DML statements using NESTED TABLE with OBJECT TYPE


    (Page 2 of 4 )

    The following SELECT statement gives the respective details of NESTED TABLE available in a single row of parent table:

    select a.CompanyName,a.NoOfYears from
    table(select experiences from employees where name='jag') a

    You can also replace the word ‘table’ with another keyword ‘the’ as follows:

    select a.CompanyName,a.NoOfYears from
    the(select experiences from employees where name='jag') a

    Any of the above two examples performs two operations.  First, it reads an ‘employees’ row with the given name.  Then, it reads the elements stored in that row’s nested table.  For better readability, I used ‘table’ instead of ‘the’.  You can even replace the field names with ‘*’ as follows:

    select a.* from
    table(select experiences from employees where name='jag') a

    By now, we already know how to retrieve information from NESTED TABLEs.  Now we need to know how to insert rows to the NESTED TABLE (not to the main table ‘employees’)?  This means I wanted to add another ‘experience’ row to the same employee ‘jag’.  The following statement does it.

    INSERT INTO
    TABLE(SELECT experiences FROM employees WHERE name = 'jag')
    VALUES
    (
       
    t_experience('efg company','Professor',2)
    );

    If you compare the above example with previous SELECT statements, you should be able to understand and there is nothing new from any angle.  Actually it is not necessary to use ‘t_experience’ in the above statement, you can also insert it as follows:

    INSERT INTO
    TABLE(SELECT experiences FROM employees WHERE name = 'jag')
    VALUES
    (
        
    'efg company','Professor',2
    );

    But for better readability, I suggest you to use the TYPE name along with values.  You can even modify the existing rows using UPDATE statement as follows:

    UPDATE
    TABLE(SELECT experiences FROM employees WHERE name = 'jag')
    set NoOfYears=5
    where CompanyName='abc company';

    You can even use DELETE statement on NESTED TABLE as follows:

    DELETE FROM
    TABLE(SELECT experiences FROM employees WHERE name = 'jag')
    where CompanyName='abc company';

    If you don’t use any OBJECT type in the NESTED TABLE (like a NESTED TABLE of varchar2, like in part-3), you can use a keyword ‘column_value’ for UPDATE or DELETE statements.  It is necessary because the NESTED TABLE does not have any specific columns to address.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, this is my article on working with nested tables in PL/SQL. You can...
       · Please check the code for topic, 'Working with PL/SQL using NESTED TABLE with...
     

       

    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 2 hosted by Hostway