Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    4

    Unanswered: Add contents of Associative array

    Hi All,

    Need help.

    I have an associative array as below:

    TYPE va_abc_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;

    Now, my va_abc_array contains below data:

    va_abc_array(1) := 40;
    va_abc_array(2) := 50;
    va_abc_array(3) := 60;
    va_abc_array(4) := 70;

    Please let me know if there is any inbuilt function which can add the contents of Associative array va_abc_array.
    => va_abc_array(1)+va_abc_array(2)+va_abc_array(3)+va _abc_array(4) = 40 + 50 + 60 + 70 which sums up to 220

    Also, please let me know any better way (considering the performance aspect) because I know I can do this using For Loop. I am avoiding using the FOR Loop because of huge data in multiple associative arrays as above which may result in performance degradation.

    Thanks,
    Arun

  2. #2
    Join Date
    Oct 2002
    Location
    Cape Town, South Africa
    Posts
    253
    Not as a PL/SQL varray. You would have to make your array a SQL type. Example:
    Code:
    dayneo@RMSD> create type va_abc_array IS TABLE OF NUMBER
      2  /
    
    Type created.
    
    dayneo@RMSD> set serveroutput on size 1000000
    dayneo@RMSD> declare
      2    l_ary va_abc_array;
      3    l_sum number;
      4  begin
      5    l_ary := va_abc_array();
      6    l_ary.extend(); l_ary(1) := 40;
      7    l_ary.extend(); l_ary(2) := 50;
      8    l_ary.extend(); l_ary(3) := 60;
      9    l_ary.extend(); l_ary(4) := 70;
     10    select sum(column_value)
     11      into l_sum
     12      from TABLE(l_ary);
     13    dbms_output.put_line('Total: ' || l_sum);
     14  end;
     15  /
    Total: 220
    
    PL/SQL procedure successfully completed.
    
    dayneo@RMSD>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •