Oracle
  Home arrow Oracle arrow Page 2 - Database Interaction with PL/SQL, part 3
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, part 3
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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, part 3 - Using TABLE Without Interacting With Database
    ( Page 2 of 5 )

    First of all, consider my apologies for inserting this topic inside an article titled as "database interactions using PL/SQL". I thought that this would be necessary, as some of our logic depends on some PL/SQL tables which don't always have to be filled with database information. And of course, using this topic, I can also introduce few new collection methods on working with PL/SQL tables.

    Let us consider the following example. Even though it is bit lengthy, I can introduce all issues at once.

    declare
       
    type t_Numtbl is table of number;
       
    v_numtbl t_numtbl := t_Numtbl(10,20,30,40,50,60,70);
    begin
        dbms_output.put_line('Displaying complete List:');
        for i in v_numtbl.first .. v_numtbl.last
        loop
           
    dbms_output.put(v_numtbl(i) || ',');
        end loop;
        dbms_output.new_line; --just skipping to next line
       
    v_numtbl.delete(3);
       
    dbms_output.put_line('Displaying complete List after deletion:');
       
    for i in v_numtbl.first .. v_numtbl.last
       
    loop
           
    if v_numtbl.exists(i) then
               
    dbms_output.put(v_numtbl(i) || ',');
           
    end if;
       
    end loop;
       
    dbms_output.new_line;
       
    dbms_output.put_line('No. of elements ' || v_numtbl.count);
    end;

    Let us consider the above program line by line. I don't think I need to cover FOR loops in the above program, as they have been already covered in my previous article.

    type t_Numtbl is table of number;

    The above line defines 't_Numtbl' as a new data type which can hold only a set of values of type 'number'.

    v_numtbl t_numtbl := t_Numtbl(10,20,30,40,50,60,70);

    The above line declares and initializes the variable 'v_numtbl' with some sample values. Make a note that they are not from database! Within the body of the above program, I used FOR loops twice to display the contents of the variable 'v_numtbl'.

    v_numtbl.delete(3);

    After displaying the values using the first FOR loop, I am deleting the third element (index starts from 1) from the table using the above statement.

    if v_numtbl.exists(i) then
       
    dbms_output.put(v_numtbl(i) || ',');
    end if;

    The above condition checks to see if the specified index exists within the table or not before trying to display it. If you don't include this, we would get an error.

    dbms_output.put_line('No. of elements ' || v_numtbl.count);

    You can use 'v_numtbl.count' to get the number of elements present within the PL/SQL table.



     
     
    >>> 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