Oracle
  Home arrow Oracle arrow Associative Arrays in Oracle PL/SQL: T...
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 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

Associative Arrays in Oracle PL/SQL: The Professional Approach
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 14
    2006-03-20

    Table of Contents:
  • Associative Arrays in Oracle PL/SQL: The Professional Approach
  • A professional approach to traversing an associative array using Oracle PL/SQL
  • Bottom to top traverse of an associative array using Oracle PL/SQL
  • Deleting individual elements in an associative array using Oracle PL/SQL
  • Deleting a set of elements in an associative array using Oracle 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

    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

    Associative Arrays in Oracle PL/SQL: The Professional Approach
    (Page 1 of 5 )

    This is the second article in a series focusing on associative arrays. In this article, we shall examine recommended methodologies for working with associative arrays efficiently.

    All the examples in this article have been tested only with Oracle 10g version 2.  I didn’t really test the examples in any of the previous Oracle versions.  I am confident enough that all of the examples should give no problems when worked with Oracle version 7.3 or above.  You can drop (or post) me a line if any of them does.  The examples can be directly copied, pasted and tested in your favorite PL/SQL environment.  They should work without any changes.

    Counting the number of elements in an associative array using Oracle PL/SQL

    Before getting into the professional approach, I have a small concept to introduce to you.  In my previous article (in the last section), I counted the number of elements using my own counter (which is less efficient). 

    Now, I shall modify the code, which is a bit more efficient than using our own counter.  Let us start with the following code.

    declare
          type year_type is table of number index by binary_integer;
          year_sales year_type;
          tot_sales   number := 0;
          i           number;
    begin
          year_sales(1990) := 34000;
          year_sales(1991) := 45000;
          year_sales(1992) := 43000;
          year_sales(1996) := 13000;
          year_sales(1998) := 53000;

          for i in 1990..2000
          loop
                if year_sales.exists(i) then
                      tot_sales := tot_sales + year_sales(i);
                      dbms_output.put_line('Sales of ' || i || ': '
    || year_sales(i));
                end if;
          end loop;
          dbms_output.put_line('Total sales: ' || tot_sales);
          dbms_output.put_line('Avg sales: ' ||
    (tot_sales/year_sales.count) );

    end;

    Within the above code, I introduced a new member into the associative array called “Count.”  It is already pre-defined for you; it keeps track of the number of elements available within the same array.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys, I am further extending the series on Associative Arrays in PL/SQL. You...
       · Your series of articles are good and informative. They are quite simple and easy to...
       · This is really a very helpful article...
       · I would have to agree that your series of articles are easy to understand and...
     

       

    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