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 
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 Best Approach
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2006-03-27

    Table of Contents:
  • Associative Arrays in Oracle PL/SQL: The Best Approach
  • Understanding the procedural approach in PL/SQL: discussion
  • Executing the PL/SQL sub-programs from within the main program
  • The final best approach to working professionally and safely

  • 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 Best Approach - Executing the PL/SQL sub-programs from within the main program
    (Page 3 of 4 )

    This is a continuation from the previous section.  Further proceeding we have the following:

    begin
          add_profit(1990,23000);
          add_profit(1991,12000);
          add_profit(1992,34000);
          add_profit(1993,45000);

          print_profits;
          print_total_profit;
    end;

    The above is the part of the main program.  In fact, the execution starts at the above "begin" and then calls the procedure "add_profit" with two parameters.  From this statement, the execution jumps to the stored procedure "add_profit" and, well, executes it. 

    Once it completes the execution of "add_profit," the control returns back to the main program and executes the next statement.  In fact, the control jumps from main program to sub program quite a number of times, depending upon necessity.

    Finally, we called the "print_profits" and "print_total_profit" without any parameters (as they don't require them), which prints all that we have added to the associative array.

    And thus we complete our discussion on the best approach to work with associative arrays.

    Extending the program a bit

    Can we still improve the program with a few more procedures? To which my answer is, Why not?  You can still make it more modular and flexible. 

    In the above program, I didn't give any approach for deleting any element within the associative array.  Now, let us extend the above with an additional procedure as follows:

    procedure delete_profit(year number) as
          begin
                year_profits.delete(year);
          end;

    Even though the above procedure is simple, it really gives you a good opportunity to delete the elements within the associative array in a very simple fashion.  Once you add the above procedure to the previous program (within the "declaration" section), modify the body of your program with the following code:

    begin
          add_profit(1990,23000);
          add_profit(1991,12000);
          add_profit(1992,34000);
          add_profit(1993,45000);

          print_profits;
          print_total_profit;

          dbms_output.put_line('-----------------');
          delete_profit(1991);
          print_profits;
          print_total_profit;
    end;

    I added a few more statements to the already existing statements, just to demonstrate the functionality of the new procedure we added to the program.  It simply displays all the elements added first and then displays all elements after deletion, separated by a line.

    More Oracle Articles
    More By Jagadish Chatarji


       · Hello guys. Thanks for giving me positive feedback on this series. And here is...
     

       

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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