Home arrow Oracle arrow Page 4 - Associative Arrays in Oracle PL/SQL: The Professional Approach

Deleting individual elements in an associative array using Oracle PL/SQL - Oracle

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.

TABLE OF CONTENTS:
  1. Associative Arrays in Oracle PL/SQL: The Professional Approach
  2. A professional approach to traversing an associative array using Oracle PL/SQL
  3. Bottom to top traverse of an associative array using Oracle PL/SQL
  4. Deleting individual elements in an associative array using Oracle PL/SQL
  5. Deleting a set of elements in an associative array using Oracle PL/SQL
By: Jagadish Chatarji
Rating: starstarstarstarstar / 22
March 20, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Until now, we simply added pairs of data to an associative array.  Now, we shall examine how to delete pairs of data from an existing associative array. 

Let us consider the following code:

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

      i := year_profits.first;
      while i <= year_profits.last
      loop
            if year_profits(i) < 0 then
                  year_profits.delete(i);
            end if;
            i := year_profits.next(i);
      end loop;

      i := year_profits.first;
      while i <= year_profits.last
      loop
            tot_profits := tot_profits + year_profits(i);
            i := year_profits.next(i);
      end loop;
      dbms_output.put_line('Total profits: ' || tot_profits);
      dbms_output.put_line('No. of years in profit: ' ||
year_profits.count);

end;

The highlighted part checks for any negative numbers within the values available in the associative array.  If anything is found, it gets deleted automatically using the DELETE member (which is also pre-defined).

In the next section, we shall examine how to delete more than one element at a time.



 
 
>>> More Oracle Articles          >>> More By Jagadish Chatarji
 

blog comments powered by Disqus
   

ORACLE ARTICLES

- Oracle Releases Communications Network Integ...
- Oracle Releases Communications Data Model 11...
- Oracle Releases PeopleSoft PeopleTools 8.52
- Oracle Integrates Cloudera Apache Distro, My...
- Oracle Releases MySQL 5.5.18
- Oracle Announces NoSQL Database Availability
- Sorting Database Columns With the SELECT Sta...
- Retrieving Table Data with the LIKE Operator
- Using the IN and BETWEEN Operators on Tables
- Clauses and Logical Operators for Retrieving...
- Limiting Rows When Retrieving Table Data
- Using Scalar Functions for Retrieving Data
- Retrieving Data with String and Arithmatic E...
- Coding the SELECT Statement
- Oracle Releases iPad Virtual Desktop and Exa...


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap

Dev Shed Tutorial Topics: