Oracle
  Home arrow Oracle arrow Page 2 - 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 
Moblin 
JMSL Numerical Library 
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
     
     
    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


       · 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

    - 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...
    - Sub-templates and More with Oracle HTML DB





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