The associative arrays, insert, rownum as index loop or not.

Hi guys,.
I want to keep this subset of rows around 5000 in a collection / table temporary but don't know how to do it. have not found much on google either.
the associative array seems good because it has no limit (and it may be more than 5000) and it offers a quick access.

DECLARE
TYPE assoc_array_str_type IS TABLE OF VARCHAR2 (32) INDEX OF PLS_INTEGER;
assoc_array_str_type v1.
BEGIN

(23231) v1: = 10;

-Select distinct rownum, rmnumber made in v1.

END;

I thought that I have use rownum as index but have the feeling that I can't 'load' a set of data both in the associative array. I need to loop and then add one don't I? is there a faster way?

You can use in bulk to collect:

declare
   type assoc_array_str_type is table of varchar2(32) index by pls_integer;
   v1 assoc_array_str_type;
begin
   select ename
   bulk collect into  v1
   from   emp;

   dbms_output.put_line('v1(1)='||v1(1));
   dbms_output.put_line('v1(2)='||v1(2));
end;
/
v1(1)=KING
v1(2)=BLAKE

Tags: Database

Similar Questions

  • need help in the associative arrays indexed by varchar

    Hi, I wanted to fill an associative array that is indexed by varchar, but I'm confused by incrementing the pointer so that the next lines gets inserted into the next available place.
    sample data:
    type ty_tb_tab_acc is record (account varchar2 (30));
    type ty_tb_indx_acct is table of index ty_tb_tab_acc by varchar2 (35);

    cursor sampls_cursor is
    Select an account in sam_tab where the clause goes in here

    say that my cursor returns 20 accounts. now, I want these 20 accounts will be inserted in the table associative ty_tb_indx_acct
    How should I buckle and incrment table?

    Please share your ideas

    user13710379 wrote:
    If this isn't the case, associatve tables approach I should use.
    My requirement:
    1.i will be 2 sliders who choose (type varchar2) account number according to diff where clause.
    2. then, I need to compare these two cusrsor account number and fill out a folder or a collection, if the two account numbers are the same.

    This must be done using SQL. Not the tables or collections or associative arrays.

    SQL is the MOST powerful language, that you have in the Oracle RDBMS. It is faster than PL/SQL, when it comes to crunch data. It is more scalable.

    So why then pull data SQL in PL/SQL (expensive) memory? And then shoot some more SQL data in memory of PL/SQL (expensive)? And then use PL/SQL loop processing to compare the two sets of data?

    SQL can do that very quickly and very efficiently - as it was designed for this specific purpose.

    See the JOIN, INTERSECT , and LESS SQL operations to compare data sets.

  • the associative arrays containing the record type, cannot be used first

    I am having trouble with the declaration of an associative array containing the Types of records and iteration using FIRST and NEXT functions.
    This problem of mine is only appear when I use that types of records, the FIRST and FOLLOWING operators work very well when you use the regular NUMBER.

    Trying to get the first element of the array, I get: ORA-06550: line 22, column 40: PLS 00382: expression is of the wrong type

    See the code snippet below. Anyone know if this can be done in PL/SQL?

    -----------------------------------------------------------------------------------------
    DECLARE


    -Set the record structure that will contain information on a post
    TYPE PostRec IS (RECORD
    post_type VARCHAR2 (4) - maybe DEB/CRED
    );

    lr_charge_back_post PostRec;

    TYPE post_table IS TABLE OF PostRec NOT NULL
    INDEX BY VARCHAR2 (4);

    assoc_posts post_table;

    BEGIN


    -lr_charge_back_post.post_type: = "asd";
    assoc_posts('1').post_type: = '1';

    lr_charge_back_post: = assoc_posts.first;

    END;
    /

    Returns the index, not the file FIRST:

    SQL> declare
      2  TYPE PostRec IS RECORD (
      3  post_type VARCHAR2(4) -- Can be DEB/CRED
      4  );
      5
      6  lr_charge_back_post  varchar2(20);
      7  TYPE post_table IS TABLE OF PostRec NOT NULL
      8  INDEX BY VARCHAR2(4);
      9
     10
     11  assoc_posts post_table;
     12
     13  BEGIN
     14
     15
     16  --lr_charge_back_post.post_type := 'asd';
     17  assoc_posts('1').post_type := '1';
     18
     19  lr_charge_back_post := assoc_posts.first;
     20  dbms_output.put_line('idx='||lr_charge_back_post);
     21  END;
     22  /
    idx=1
    
    PL/SQL procedure successfully completed.
    
    SQL> declare
      2  TYPE PostRec IS RECORD (
      3  post_type VARCHAR2(4) -- Can be DEB/CRED
      4  );
      5
      6  lr_charge_back_post  varchar2(20);
      7  TYPE post_table IS TABLE OF PostRec NOT NULL
      8  INDEX BY VARCHAR2(4);
      9
     10
     11  assoc_posts post_table;
     12
     13  BEGIN
     14
     15
     16  --lr_charge_back_post.post_type := 'asd';
     17  assoc_posts('idx').post_type := '1';
     18  lr_charge_back_post := assoc_posts.first;
     19  dbms_output.put_line('idx='||lr_charge_back_post);
     20  END;
     21  /
    idx=idx
    
    PL/SQL procedure successfully completed.
    

    Max
    http://oracleitalia.WordPress.com

  • For automatic indexing loop should not index empty array

    Hi guys,.

    I wanted to say in this VI remove empty elements in the table. He worked for table 1 d, but as soon as I gave him a table 2D, for some reason that I was unable to remove empty elements:

    sdfsdfsdfadgadf wrote:

    So when I was debugging, I saw at the 3rd row and 4th iteration of line, out of the inside OF the terminal loop index outter loop is [].

    Should not the terminal of the index of the outer loop treat [] as 'skip it '?

    In this case, the tunnel of indexation in the outer loop takes an empty 1-d array and adds it as a line to the 2D table. Because the 2D tables can not be serrated, it fills the remaining elements of the line (all) with the default value. Maybe we could say that an empty array should mean 'add all', but this behavior goes back very far and I don't know what effect this would have. As mentioned, it is easy enough to do what you want with a conditional append in the outer loop.

    sdfsdfsdfadgadf wrote:

    I mean what you described certainly applies if [] a something, but in this case it didn't. To prove the point, try something like this:

    Check the size of the table. You will find that it is 3,0,0. In other words, you have 3 pages, each with an empty 2D array, which is exactly what builds your code.

    I try to avoid dealing with > 2D paintings and which deals with the cases where they can be empty, so I don't remember the details of why this happens, but IIRC, it follows the rules of the system.

  • error of dynamics of the associative array (pl/sql), please help

    Function down I can hard-coded but not able to go to dynamically can u please friends

    CREATE OR REPLACE FUNCTION FN_SUBSCRIPTION_BEHAVIOUR(P_YYMM IN VARCHAR2) RETURN VARCHAR2
    AS
    ARR_LIST APEX_APPLICATION_GLOBAL. VC_ARR2;
    Typ_array. ARRAY TYPE IS VARCHAR2 (16);
    array_final typ_array;
    V_ARRAY VARCHAR2 (2000);
    v_out VARCHAR2 (2000);
    v_result VARCHAR2 (2000);
    BEGIN
    ARR_LIST: = APEX_UTIL. STRING_TO_TABLE (P_YYMM, ',');
    Select LISTAGG (fid_value, ',') IN GROUP (ORDER BY fid_value) BY v_array
    of filter_detail, filter_master
    where fil_id = fid_fil_id
    and fil_position = 15
    AND NVL (fid_ACTIVE, 'Y') = 'Y ';
    array_final: = typ_array (v_array); Commented (1102,1101,1012,1011,1010,1009,1008,1007,1006,1005,1004,1003,1002,1001);
    I'm looping 1.array_final.count
    If array_final (i) in (arr_list (I)) then v_result: = '1';--Commented--(1002,1003,1007)
    Another v_result: = '0';
    end if;
    v_out: = v_out | v_result;
    end loop;
    Return v_out;
    END;


    my output is

    00000001000110

    Published by: V on March 23, 2011 21:42

    Published by: V on March 23, 2011 22:24

    Published by: V on March 23, 2011 23:00

    Published by: V on March 24, 2011 12:57 AM

    Hello

    Please check below, hope this helps.

    SQL>
    SQL> DROP TABLE tmp
      2  /
    
    Table dropped
    SQL> CREATE TABLE tmp ( col1 NUMBER)
      2  /
    
    Table created
    SQL> INSERT INTO tmp
      2      SELECT 1001 FROM DUAL UNION
      3      SELECT 1002 FROM DUAL UNION
      4      SELECT 1003 FROM DUAL UNION
      5      SELECT 1004 FROM DUAL UNION
      6      SELECT 1005 FROM DUAL UNION
      7      SELECT 1006 FROM DUAL UNION
      8      SELECT 1007 FROM DUAL UNION
      9      SELECT 1008 FROM DUAL UNION
     10      SELECT 1009 FROM DUAL UNION
     11      SELECT 1010 FROM DUAL UNION
     12      SELECT 1011 FROM DUAL UNION
     13      SELECT 1012 FROM DUAL UNION
     14      SELECT 1101 FROM DUAL UNION
     15      SELECT 1102 FROM DUAL
     16  /
    
    14 rows inserted
    SQL> COMMIT
      2  /
    
    Commit complete
    SQL> CREATE OR REPLACE FUNCTION FN_SUBSCRIPTION_BEHAVIOUR(P_YYMM IN VARCHAR2)
      2    RETURN VARCHAR2 AS
      3    ARR_LIST APEX_APPLICATION_GLOBAL.VC_ARR2;
      4    TYPE typ_array IS TABLE OF VARCHAR2(16);
      5    array_final typ_array;
      6    V_ARRAY     VARCHAR2(2000);
      7    v_out       VARCHAR2(2000);
      8    v_result    VARCHAR2(2000);
      9  BEGIN
     10    select LISTAGG(col1, ',') WITHIN
     11     GROUP(
     12     ORDER BY col1)
     13      INTO v_array
     14      from tmp;
     15    ARR_LIST := APEX_UTIL.STRING_TO_TABLE(v_array, ',');
     16    for i in 1 .. ARR_LIST.count loop
     17      if (INSTR(P_YYMM, ARR_LIST(i)) > 0) then
     18        v_result := '1';
     19      else
     20        v_result := '0';
     21      end if;
     22      v_out := v_out || v_result;
     23    end loop;
     24    return v_out;
     25  END;
     26  /
    
    Function created
    SQL> DECLARE
      2     l_out   VARCHAR2(2000);
      3  BEGIN
      4     l_out := FN_SUBSCRIPTION_BEHAVIOUR('1002,1003,1004');
      5     dbms_output.put_line(l_out);
      6  END;
      7  /
    
    01110000000000
    
    PL/SQL procedure successfully completed
    
    SQL> 
    

    Ameya

  • Why the execution time increases with a while loop, but not with "run continuously?

    Hi all

    I have a problem of severe weather that I don't know how to fix it because I don't know exactly where it comes from.

    I order two RF switches via a data acquisition card (NI USB-6008). One job at the same time can be selected on each switch. Basically, the VI created for this feature (by a colleague) resets all the outputs of acquisition data and active then those desired. It has three entrances, two chain simp0le controls and a cluster table, that contains the list of all the outputs and some practical information to know what is connected (specific to my application).

    I use this VI in a complex application, and I have some problems with the execution time, which increased whenever I said the VI, so I did a test VI (TimeTesting.vi) to determine where the problem came. In this special VI I record the execution time in a csv file to analyze then with excel.

    After several tries, I found that if I run this criterion VI with the while loop, execution on every cycle time increases, but if I remove the while loop and use the funtionnality "Continuous run", the execution time remains the same. In my high level application, I have while loops and events, and so the runtime increases too.

    I someone could explain to me why execution time increases and how can we avoid this? I have attached my VI test and the necessary subVIs, as well as an image of a graph that shows the execution time with a while loop and «run permanently»

    Thanks a lot for your help!

    Your SetReset_DO VI creates a channel whenever it is called.  And that you never delete a task.

    When running continuously, that it's as if it only runs once and LabVIEW has internal mechanisms to close references that will not be used again.  When a VI is used as a Subvi, LV does not know if she will be called again, and lacks these things until the first level VI stops. You have a memory leak.

    Just as you open and close your file outside the loop for, create your channel out of the loop.

    Lynn

  • When I insert a blank CD the message is "insert a blank disc" he does not recognize the empty space and says zero bytes free.

    I have a new desktop computer Dell 9010.  The CD/DVD drive is 16 x DVD-ROM SATA.  When I insert a CD with files it contains with free space, it says that I need more free space.  It does not recognize free space.   (free 0 bytes)

    When I insert a blank disc the message is "Please insert a new disc.  The drive doesn't recognize free space on a disk.  It's the same thing with discs CD - R and CD - RW (52 X and 12 X respectively).

    I have a new desktop computer Dell 9010.  The CD/DVD drive is 16 x DVD-ROM SATA.  When I insert a CD with files it contains with free space, it says that I need more free space.  It does not recognize free space.   (free 0 bytes)

    When I insert a blank disc the message is "Please insert a new disc.  The drive doesn't recognize free space on a disk.  It's the same thing with discs CD - R and CD - RW (52 X and 12 X respectively).

    ====================================
    The following items may be worth a visit:
     
    Your CD or DVD drive cannot read or write media
    http://support.Microsoft.com/mats/cd_dvd_drive_problems/en-us

    (982116) your CD or DVD drive is missing
    or is not recognized by Windows or other programs
    http://support.Microsoft.com/kb/982116
    (Windows XP / Windows Vista / Windows 7)

    (scroll down and expand the section: "Let me fix it myself")

  • An associative array, how the records using the loop counter?

    In the associative array, how the records using the loop counter? for example
    declare
        type population is table of number index by varchar2(64);
        city_population population;   
    begin
        city_population('Samillve') := 200;
        city_population('Lindenhurst') := 300;    
        
        for i in 1 .. city_population.count
        loop
            dbms_output.put_line(city_population(i)); -- compiler error
        end loop;
    end;
    /

    That would look like

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2      type population is table of number index by varchar2(64);
      3      city_population population;
      4      l_index varchar2(64);
      5  begin
      6      city_population('Samillve') := 200;
      7      city_population('Lindenhurst') := 300;
      8      l_index := city_population.first;
      9      while( l_index IS NOT NULL )
     10      loop
     11          dbms_output.put_line(city_population(l_index ));
     12          l_index := city_population.next(l_index);
     13      end loop;
     14* end;
    SQL> /
    300
    200
    
    PL/SQL procedure successfully completed.
    

    Justin

  • Associative array of index files by varchar2 - PLS 00382

    I have a SQL anonymous block that creates a report. At the end of each section, I need to summarize the data by "renting". The list of locations is finished (approx. 15 in a table) and not all sections will have data for each location, but I want the locations to order the same so I thought I'd use an associative array to store summary data. But when I try to initialize the associative array (I simply put the slots in the array in the "correct" order) I receive PLS-00382 expression is of the wrong type.

    Here is the code (the lines where the error occurs are in bold):

    TYPE summary_data () IS RENDERING
    Summary1 NUMBER,
    NUMBER of summary2
    NUMBER of summary3
    );

    Summ_arr TYPE IS TABLE of summary_data INDEX OF VARCHAR2 (5);

    location_summary summ_arr;

    aLoc VARCHAR2 (5);

    PROCEDURE init_summ (aSummArr IN OUT summ_arr) IS
    BEGIN
    aSummArr.Delete;

    BEGIN
    FOR in aLoc (select name - name is VARCHAR2 (5))
    table
    control key)
    LOOP
    aSummArr (aLoc) .summary_1: = 0;
    aSummArr (aLoc) .summary_2: = 0;
    aSummArr (aLoc) .summary_3: = 0;
    END LOOP;
    EXCEPTION
    -exception handling
    END;

    END;

    If this is not allowed, or I do something wrong? I tried substituting:

    Summ_arr TYPE IS TABLE of summary_data INDEX OF VARCHAR2 (5);

    with

    Summ_arr TYPE IS TABLE of summary_data INDEX table.key%TYPE;

    Nothing helps.

    Thanks in advance for your help with this.

    ANNUAL GENERAL MEETING

    ALOC is a record variable. You need to refrence the column in the file said. So, something like this:

    aSummArr(aLoc.name).summary_1 := 0;
    

    Cheers, APC

  • How to see the output of an associative array in procedure

    Hello
    I tried the following code
    And confused about the research at the exit of the associative array.
    CREATE OR REPLACE PACKAGE test_pak1
    AS
       FUNCTION map_object (obj_typ_in VARCHAR2)
          RETURN VARCHAR2;
    
       CURSOR c_c1
       IS
          SELECT * FROM emp;
    
       TYPE test_ttyp IS TABLE OF c_c1%ROWTYPE
                            INDEX BY PLS_INTEGER;
    
       PROCEDURE search_obj (obj_type VARCHAR2);
    END;
    
    CREATE OR REPLACE PACKAGE BODY test_pak1
    AS
       FUNCTION map_object (obj_typ_in VARCHAR2)
          RETURN VARCHAR2
       IS
       BEGIN
          dopl ('Hello');
          RETURN abc;
       END;
    
       PROCEDURE search_obj (obj_type VARCHAR2)
       IS
          test_tab   test_ttyp;
       BEGIN
            DOPL  (test_tab);
          end;
       END;
    In the above code, I want to see the output of the test_tab located in the search_obj procedure.

    could you please help me in this

    Thank you

    Hi, smile,

    If you want to see records, you must put the lines in your table. Here's a solution: in this solution, I only edit the search_obj procedure of your package like this:

     PROCEDURE search_obj (obj_type VARCHAR2)
       IS
          test_tab   test_ttyp;
          test_tab_r   c_c1%ROWTYPE;
       BEGIN
            --test_tab;
            --Here we put something in test_tab
            OPEN c_c1;
    
            LOOP
                 Fetch c_c1 into test_tab_r;
                 exit when c_c1%NOTFOUND;
                 test_tab(test_tab.COUNT + 1) := test_tab_r;
             END LOOP;
            CLOSE c_c1;   
    
            FOR i IN 1 .. test_tab.COUNT LOOP
              dbms_output.put_line(test_tab(i).empno);
           END LOOP;
    
       END;
    

    Here is the result:

    SQL> exec test_pak1.search_obj('parameter_not_used_in_the_procedure');
    7369
    7499
    7521
    7566
    7654
    7698
    7782
    7788
    7839
    7844
    7876
    7900
    7902
    7934
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • CURSOR for loops or an associative array

    I just want to know the advantages and disadvantages of the CURSOR for loops. As a general rule, what guys do you prefer: associative array with CURSOR for loops?


    If you use the CURSOR for loop, is it not difficult to debug?

    PL/SQL Developer, I do not see what values are stored in the CURSOR for loop (in SP master_proc below) as
    There are no variables to watch. Not sure if the TOAD can show these values

    If I had used an associative array (master_proc2 below), I can see the values stored in the table by clicking on "show Collection"variable in PL/SQL developer.




    create table emp2 as select * from emp;
    
    
    create or replace procedure my_proc(p_empno in number)
    as
    begin
    update emp2 set sal=sal+100 where empno=p_empno;
    end;
    /
    
    --Using CURSOR FOR loop
    
    create or replace procedure master_proc
    as
    begin
         for rec in (select empno from emp2 where empno>7700)
         loop
              my_proc (rec.empno);
         end loop;
    end;
    /
    
    -- Using Associative arrays
    create or replace procedure master_proc2
    as
    type v_empno_type is table of number index by pls_integer;
    v_empno v_empno_type;
    
    begin
    select empno bulk collect into v_empno from emp2 where empno>7700;
    
    for i in 1..v_empno.count
     loop
        my_proc (v_empno(i));
     end loop;
    end;
    /

    VitaminD wrote:
    Thank you Tubby. If you are faced with a situation where you MUST use a loop. Then you would go to associative arrays rather than CURSOR FOR loops. Right?

    Doesn't happen too often, but if/when then I would do as I said in my first post. Use the transformation, the collection table in BULK and FORALLs.

    If we use your example posted, I would NOT spend a single table (in a loop mode) value I would be transmitted in the OVERALL picture and treat it with FORALL.

    So, I would still use neither of the approaches that you mentioned.

  • What is the preferred means of data transmission as a type of record between the nested table of pl/sql program or an associative array

    What is the preferred means of data transmission in the associative array of the nested table record vs

    Choose between Nested Tables and associative arrays

    The two nested tables and associative arrays (formerly index - by tables) use similar index notation, but they have different characteristics when it comes to persistence and ease of passing parameters.

    Nested tables can be stored in a column of data, but can of associative arrays. Nested tables can simplify the SQL operations where you would normally join a single-column table with a larger table.

    Associative arrays are appropriate for relatively small lookup tables where the collection can be constructed in memory whenever a procedure is called or a package is initialized. They are good for the collection of the information volume is unknown beforehand, because there is no fixed limit on their size. Their index values are more flexible, as associative array indices can be negative, can be no sequential and can use values of string instead of numbers.

    PL/SQL automatically converts between the bays of the host and the associative arrays that use values of digital keys. The most effective way to move the collections to and from the database server is to implement data values in associative arrays, and then use these associative arrays with erections in bulk (the FORALL statement or BULK COLLECT clause).

    With the help of documents and Collections of PL/SQL

    Read this:

    How to pass the record set as a parameter of the procedure.

    https://community.Oracle.com/thread/2375173?TSTART=0

  • Difference between the nested table and an associative array

    Hello
    While going through the link http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm
    I came across the statement that
    Nested tables can be stored in a column of data, but of associative arrays

    So I tried the following statement for the associative arrays where he works
    create type t_nm is table of number index by binary_integer
    The t_nm of type above name is stored in USER_TYPES.


    So how can we say that associative arrays can not be stored in DB.

    Please correct me if I'm wrong.

    Thank you

    Published by: smile on April 8, 2011 02:42
    SQL> drop type t_num;
    
    Type dropped.
    
    SQL> create type t_num table of number index by binary_integer;
      2  /
    
    Warning: Type created with compilation errors.
    
    SQL> desc t_num;
    ERROR:
    ORA-24372: invalid object for describe
    
    SQL> set lines 999
    SQL> select * from user_types;
    
    TYPE_NAME                      TYPE_OID                         TYPECODE                       ATTRIBUTES
    ------------------------------ -------------------------------- ------------------------------ ----------
    T_NUM                          57417E92AD25409CB858D339570A0F56 OBJECT                                  0 
    
    SQL> select object_name, object_type, status from user_objects where object_name = 'T_NUM';
    
    OBJECT_NAME                                                                                                                      OBJECT_TYPE         STATUS
    -------------------------------------------------------------------------------------------------------------------------------- ------------------- -------
    T_NUM                                                                                                                            TYPE                INVALID
    
    SQL> 
    

    You might have missed the error into a TOAD.

    Concerning

    REDA

  • Using associative arrays in query

    Hi all

    Please see my schedule. It works very well

    [CODE]

    DECLARE

    type mechanics_type_tab is table of index varchar2 (15) by varchar2 (15);

    l_mechanics_type mechanics_type_tab;

    L_BULLETIN t_tfo_wf_varchar_table:=t_tfo_wf_varchar_table();

    l_count pls_integer: = 0;

    BEGIN

    FOR I IN (select bulletin_id, mechancs_type_id

    of TFO_BULLETIN_PROMO_MECHANICS

    where mechancs_type_id is not null) LOOP

    l_count: = l_count + 1;

    l_mechanics_type (i.bulletin_id): = i.mechancs_type_id;

    l_mechanics_type (i.mechancs_type_id): = i.mechancs_type_id;

    L_BULLETIN.extend;

    L_BULLETIN (l_count): = i.bulletin_id;

    END LOOP;

    FOR J IN (SELECT TABLE COLUMN_VALUE (L_BULLETIN)) LOOP - this will change

    DBMS_OUTPUT. Put_line ('COLUMN_VALUE =' | l_mechanics_type (J.COLUMN_VALUE));

    END LOOP;

    / * does not

    Insert into test_table (test1)

    SELECT values l_mechanics_type (COLUMN_VALUE) OF TABLE (L_BULLETIN); */

    END;

    [/ CODE]

    instead of the code below:

    FOR J IN (SELECT TABLE COLUMN_VALUE (L_BULLETIN)) LOOP - this will change

    DBMS_OUTPUT. Put_line ('COLUMN_VALUE =' | l_mechanics_type (J.COLUMN_VALUE));

    END LOOP;

    When I did as below

    [CODE]

    insert into test_table (test1) to

    SELECT values l_mechanics_type (COLUMN_VALUE) OF TABLE (L_BULLETIN);

    [/ CODE]

    It does not work. Why it does not work.

    Please note that in the real-world scenario, there are several fields to insert for test_table and test1 is one of them.

    Just because the associative arrays are not supported in SQL before ORACLE 12 c.

    HTH

  • Associative arrays

    Quoting docs.oracle.com lines


    Associative arrays are used to represent sets of data of arbitrary size, with quick search of an individual element without its position in the table and without
    having to loop through all the elements in the array. Here is a small example

    DECLARE
    TYPE population_type IS TABLE OF NUMBER INDEX OF VARCHAR2 (64);
    country_population population_type;
    continent_population population_type;
    howmany NUMBER;
    that VARCHAR2 (64);
    BEGIN
    country_population ('Greenland'): = 100000; -Creates the entry
    country_population ('Iceland'): = 750000; -Creates the entry
    -Research associated with a value chain
    howmany: = country_population ('Greenland');
    continent_population ('Australia'): = 30000000;
    continent_population ('Antarctica'): = 1000; -Creates the entry
    continent_population ('Antarctica'): = 1001; -Replaces the previous value
    -Returns "Antarctic" which comes first in alphabetical order.
    who: = continent_population. FIRST;
    -Returns "Australia", which comes last in the alphabetical order.
    who: = continent_population. LAST;
    -Returns the value corresponding to the last key, in this
    -case of the Australia population.
    howmany: = continent_population (continent_population. LAST);
    END;
    /



    my doubt is in what regards the statement "with a quick search of an individual element without its position in the table".can someone give a small relevant example. Therefore the associative arrays is also appropriate for relatively small lookup tables where the collection can be constructed in memory eachtime, a procedure is called? Thanks in advance...

    >
    my doubt is in what regards the statement "with a quick search of an individual element without its position in the table".can someone give a small relevant example.
    >
    Think of it as gradually close equivalent to a hash of key/value pairs. When you want to insert an item provide you the key, Oracle axe key to find the entry in the hash table. It doesn't matter if the entry is the first, last, or any other arbitrary position in the table.
    >
    Therefore the associative arrays is also appropriate for relatively small lookup tables where the collection can be constructed in memory eachtime, a procedure is called?
    >
    The scope of the variables of the procedure is only the duration of the procedure. They are built when the procedure is called and destroyed when the procedure ends.

    If any associative array created in the procedure must be small to minimize the impact on the performance of the table fill. If the procedure performs complex calculations or ETL one record at a time, it is more efficient to get a value from the array instead of having to re - query a database table for him.

    For example, for the United States, a list of 50 State and their full name abbreviations that can be stored in an associative array and procedure could extract the code of the State of a data element, and quickly find the name of the State of the table. It would be faster than executing a query on the database on a lookup table.

Maybe you are looking for