Oracle
  Home arrow Oracle arrow Page 3 - 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 
 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

    Dell PowerEdge Servers

    Associative Arrays in Oracle PL/SQL: The Professional Approach - Bottom to top traverse of an associative array using Oracle PL/SQL
    (Page 3 of 5 )

    In the last sections, we have already seen several pre-defined members associated with associative arrays.  Now, let us look into the same scenario with a small difference in traversing.

    The last two sections concentrated on a top-down approach to traversing an associative array.  Now, we shall focus on a bottom-top approach to traversing the same.  Let us first go through the 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;

          i := year_sales.last;
          while i >= year_sales.first
          loop
                tot_sales := tot_sales + year_sales(i);
                dbms_output.put_line('Sales of ' || i || ': ' ||
    year_sales(i));
                i := year_sales.prior(i);
          end loop;
          dbms_output.put_line('Total sales: ' || tot_sales);
          dbms_output.put_line('Avg sales: ' ||
    (tot_sales/year_sales.count) );

    end;

    Shown below are the only modifications I made to the above code.  I replaced the following:

    i := year_sales.first;
          while i <= year_sales.
    last
          loop
                tot_sales := tot_sales + year_sales(i);
                dbms_output.put_line('Sales of ' || i || ': ' ||
    year_sales(i));
                i := year_sales.next(i);
          end loop;

    with this:

          i := year_sales.last;
          while i >= year_sales.
    first
          loop
                tot_sales := tot_sales + year_sales(i);
                dbms_output.put_line('Sales of ' || i || ': ' ||
    year_sales(i));
                i := year_sales.prior(i);
          end loop;

    Please observe the color highlighting in the code fragments above.  The rest is the same, and I leave it for you to understand.

    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