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.

Tags: Database

Similar Questions

  • How to: compare 2 associative arrays element-by-element

    After playing, I decided to go with the approach of the two sets of data of their own associative array.  The code and the results of this are below.  My question is the comparison.  For each element within the matrix of order, check all the items in the details table to see if there's a football game.  If there is a match > > > move to the next item in the control panel and check all the items in the details table to see if there is a football game.  Go until the whole is considered to be a match (in number of rows and values).  If no match, take the exit.

    Below, you'll see my logic to get both sets of data into their respective tables.  The results with a note attached to one of the elements is also pasted here (hereinafter the code).

    DECLARE

    TYPE details_t () IS RENDERING

    SIDE AUTO_RECIPE_DETAILS. SIDE % TYPE.

    REF_DES AUTO_RECIPE_DETAILS. REF_DES % TYPE,

    PART_NUM AUTO_RECIPE_DETAILS. PART_NUM % TYPE

    );

    TYPE details_type IS TABLE OF details_t INDEX OF AUTO_RECIPE_DETAILS. PART_NUM % TYPE;

    details_recipe details_type;

    pid_recipe details_type;

    compare_result details_type;

    CURSOR details_cur

    IS

    SELECT A FACE, REF_DES, PART_NUM

    OF AUTO_RECIPE_DETAILS

    WHERE RECIPE_NAME =' 40617-000001;

    CURSOR pid_cur

    IS

    SELECT cl. SIDE, lacpa. REF_DES, NVL(oecl.COMPONENT_ID, 'NOT APPLIED') AS PART_NUM

    OF ORDER_ERP_COMPS_LIST lacpa

    RIGHT OUTER JOIN CAD_LOCS cl

    ON cl. REF_DES = LACPA. REF_DES

    WHERE lacpa. ORDER_NUM = "PSY142420."

    AND CL. FAB = '38112';

    counter_d number (10): = 0;

    counter_p number (10): = 0;

    comp_counter number (10): = 0;

    BEGIN

    FOR rec IN details_cur

    LOOP

    counter_d: = counter_d + 1;

    details_recipe (counter_d). SIDE: = rec. SIDE;

    details_recipe (counter_d). REF_DES: = rec. REF_DES;

    details_recipe (counter_d). PART_NUM: = rec. PART_NUM;

    END LOOP;

    FOR rec IN pid_cur

    LOOP

    counter_p: = counter_p + 1;

    pid_recipe (counter_p). SIDE: = rec. SIDE;

    pid_recipe (counter_p). REF_DES: = rec. REF_DES;

    pid_recipe (counter_p). PART_NUM: = rec. PART_NUM;

    END LOOP;

    -for each pid_recipe element, double-check each record in details_recipe to see if there is an item matching (record)...

    FOR indx_d IN details_recipe. FIRST... details_recipe. LAST

    LOOP

    DBMS_OUTPUT. Put_line (details_recipe (indx_d). SIDE | ', ' || details_recipe (indx_d). REF_DES | ', ' || details_recipe (indx_d). PART_NUM);

    END LOOP;

    DBMS_OUTPUT. PUT_LINE ('IN THE SECOND PART OF IT!');

    FOR indx_p IN pid_recipe. FIRST... pid_recipe. LAST

    LOOP

    DBMS_OUTPUT. Put_line (pid_recipe (indx_p). SIDE | ', ' || pid_recipe (indx_p). REF_DES | ', ' || pid_recipe (indx_p). PART_NUM);

    END LOOP;

    END;

    /



    RESULT:


    DETAILS TABLE

    RECIPE FOR THE DETAILS TABLE:

    B, R28, 34315-26R7

    B, R38, 34315-4990

    B, R40, 34152-1R60

    B, R45, 34315-1002

    B, R46, 34315-3011

    B, R48, 34152-1004

    B, R55, 34315-5901

    B, R64, NOT APPLIED

    B, R77, 34315-4992



    CONTROL PANEL

    THE RECIPE IS CALCULATED IN THE ORDER ITSELF:

    B, C01, 39412-334 / / for that one single item-> check all the items from the table (above) details Table and see if an element matches.  Move to the next item if there is a match...

    B, C02, 39412-334

    B, C03, NOT APPLIED

    T, C11, 27249-105

    T, C13, 35404-104

    T, C14, 27531-224

    T, C15, 35404-104

    T, C18, 27249-105

    T, C19, 27531-224

    CHANGED:

    THIS... is the solution to my original question.  I had a little mistake that I set between this and my last post with this code.  Just in case a person who could use an example like that falls on this thread.

    FOR index_p IN pid_recipe. FIRST... pid_recipe. LAST

    LOOP

    Result WHEN the OUTPUT = 1;

    FOR index_d IN details_recipe. FIRST... details_recipe. LAST

    LOOP

    IF (pid_recipe (index_p). SIDE = details_recipe (index_d). SIDE)

    AND (pid_recipe (index_p). REF_DES = details_recipe (index_d). REF_DES)

    AND (pid_recipe (index_p). PART_NUM = details_recipe (index_d). PART_NUM)

    THEN

    EXIT;

    ON THE OTHER

    DBMS_OUTPUT. Put_line("IT WAS NOT a MATCH");

    result: = 1;

    EXIT;

    END IF;

    END LOOP;

    END LOOP;

    DBMS_OUTPUT. Put_line('LOOP OUT');

  • 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

  • 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

  • Associative array

    I have a table proj_test .i want to recover the data in the associative array.

    How to do?

    create table proj_test as  
      select 1 as id, 1 as rn, 'Fred' as nm from dual union all  
      select 1,2,'Bloggs' from dual union all  
      select 2,1,'Scott' from dual union all  
      select 2,2,'Smith' from dual union all  
      select 3,1,'Jim' from dual union all  
      select 3,2,'Jones' from dual  
    
    

    You need not Associative array if you do a bulk of collect. You can use the nested PL/SQL table type.

    11g and more

    declare

    is of type tbl table of the proj_test % rowtype;

    tbl l_tbl;

    Start

    SELECT id, rn, nm bulk collect into l_tbl

    of proj_test;

    because me in 1.l_tbl.count

    loop

    dbms_output.put_line

    (

    RPAD (to_char (l_tbl (i) USER.USER), 10, ' ')

    || RPAD (to_char (l_tbl (i). (RN), 10, ' ')

    || l_tbl (i) .nm

    );

    end loop;

    end;

    Before 11 g

    declare

    type id_tbl is table of the proj_test.id%type;

    type rn_tbl is table of the proj_test.rn%type;

    type nm_tbl is table of the proj_test.nm%type;

    id_tbl l_id;

    l_rn rn_tbl;

    l_nm nm_tbl;

    Start

    SELECT id, rn, nm bulk collect into l_id, l_rn, l_nm

    of proj_test;

    because me in 1.l_id.count

    loop

    dbms_output.put_line

    (

    RPAD (to_char (l_id (i)), 10, ' ')

    || RPAD (to_char (l_rn (i)), 10, ' ')

    || l_nm (i)

    );

    end loop;

    end;

  • Error renaming dates to an associative array of type date

    Hi all

    I am facing issue while assigning dates in an associative array of type date:

    Oracle version:

    SQL > select * from v version $;

    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production
    CORE 10.2.0.1.0 Production
    AMT for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production

    Stored procedure, I try to write is as follows

    1. create or replace procedure (jp1)
    2. p_start_date default date trunc(sysdate,'MM')
    3. p_end_date date default trunc (sysdate)
    4. )
    5. is
    6. number of l_no_of_days;
    7. type t_date_id is table of date
    8. index by pls_integer;
    9. l_date_id_arr t_date_id;
    10. Start
    11. l_no_of_days: = p_end_date - p_start_date;
    12. for i from 0
    13. .. l_no_of_days - 1
    14. loop
    15. l_date_id_arr: = p_start_date + i;
    16. dbms_output.put_line (p_start_date + i);
    17. end loop;
    18. end;
    19. /

    I get error on line 14 when compiling it. and the error message is as follows:

    JP1 PROCEDURAL errors:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    14/5 PL/SQL: statement ignored
    14/22 PLS-00382: expression is of the wrong type

    While studying this, I tried the value of (p_start_date + i) using dbms_output.put_line and the output is so date itself.

    1. create or replace procedure (jp1)
    2. p_start_date default date trunc(sysdate,'MM')
    3. p_end_date date default trunc (sysdate)
    4. )
    5. is
    6. number of l_no_of_days;
    7. type t_date_id is table of date
    8. index by pls_integer;
    9. l_date_id_arr t_date_id;
    10. Start
    11. l_no_of_days: = p_end_date - p_start_date;
    12. for i from 0... l_no_of_days-1

    13. loop
    14. -l_date_id_arr: = p_start_date + i;
    15. dbms_output.put_line (p_start_date + i);
    16. end loop;
    17. end;
    18. /

    output of the

    1. exec jp1

    is as follows:

    1ST DECEMBER 13

    2 DECEMBER 13

    3 DECEMBER 13

    DECEMBER 4, 13

    5 DECEMBER 13

    DECEMBER 6, 13

    7 DECEMBER 13

    DECEMBER 8, 13

    9 DECEMBER 13

    DECEMBER 10, 13

    DECEMBER 11, 13

    DECEMBER 12, 13

    13 DECEMBER 13

    14 DECEMBER 13

    15 DECEMBER 13

    16 DECEMBER 13

    17 DECEMBER 13

    18 DECEMBER 13

    I see the release date itself. so why he throws error while the same assignment to an associative array of type date.

    I tried Google too for the same but without success.

    Any help is appreciated in this regard not or any pointer another thread on the internet or in this forum.

    Thanks in advance

    Jagdeep Seven

    Read associative arrays:

    1. create or replace procedure (jp1)
    2. p_start_date default date trunc(sysdate,'MM')
    3. p_end_date date default trunc (sysdate)
    4. ) is
    5. number of l_no_of_days;
    6. type t_date_id is table of date
    7. index by pls_integer;
    8. l_date_id_arr t_date_id;
    9. Start
    10. l_no_of_days: = p_end_date - p_start_date;
    11. because me in 0.l_no_of_days - 1
    12. loop
    13. l_date_id_arr (I): = p_start_date + i;
    14. dbms_output.put_line (p_start_date + i);
    15. end loop;
    16. end;

    ----

    Ramin Hashimzade

  • Associative array as a type of database

    As it is very well create an associative array inside a stored procedure:

      type urltype  is table of varchar2(32767) index by varchar2(30);
    
    

    Can it be created as a type of database at the level of the schema?

    Brian.McGinity wrote:

    As it is very well create an associative array inside a stored procedure:

    1. type urltype is the table of index varchar2 (32767) by varchar2 (30);

    Can it be created as a type of database at the level of the schema?

    Non - associative arrays are a function of PL/SQL.

    See table 5-1 in the doc of the PL/SQL language for a description of each type of collection and where (pl/sql, sql, etc.) they can be used.

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/composites.htm#CHDBHJEI

  • Cannot run the autonomous block for input of associative array parameter

    Hello

    I have created an associative array in a package-PKG_CMT_DAP

    TYPE r_supply_type_id IS RECORD(
                                   supply_type_id            varchar2(50));
    TYPE t_supply_type_id IS TABLE OF r_supply_type_id INDEX BY BINARY_INTEGER;
    l_supply_type_id t_supply_type_id;
    

    Later created a test procedure with an input of the above kind parameter

    create or replace
    procedure test_prc(p_in_st_id IN PKG_CMT_DAP.t_supply_type_id)
    AS
    v_input1 number;
    v_input2 number;
    BEGIN
    FOR z IN 1..p_in_st_id.COUNT 
    LOOP
    DBMS_output.put_line(p_in_st_id(z)supply_type_id);
    END LOOP;
    END test_prc;
    

    How to update successfully.

    Created a stand-alone as block below

    DECLARE
    BEGIN
    test_prc(p_in_st_id=>(100,200,300));
    END;
    

    Above am past in 100,200,300 as an input string, and the expected output should display all the numbers above on the screen.

    But it throws the below error

    Error report:
    ORA-06550: line 3, column 1:
    PLS-00306: wrong number or types of arguments in call to 'TEST_PRC'
    ORA-06550: line 3, column 1:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    

    Could you please help me where I am doing wrong?

    Kind regards

    Claudy Kotekal

    Claudy,

    While calling the procedure, you must declare the variable of type table. Give the values for the elements in the begin block and then pass that variable in the procedure. Something like below:

    Declare

    in_array PKG_CMT_DAP. r_supply_type_id;

    Begin

    in_array (1) .supply_type_id: = 100;

    in_array (2) .supply_type_id: = 200;

    in_array (3) .supply_type_id: = 300;

    test_prc (in_array);

    end;

    NOTE: There might be a few problems with my code syntax, but logic would be same.

    Try this and let me know.

    Thank you

  • 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

  • Difference between an associative array and Nested table

    Hello

    Can you please tell me, what is the main differences between associative array and Nested table. I'm not sure, in this case we are to use.

    Thank you and best regards,
    Sanjeev.

    user13483989 wrote:
    Hello

    Can you please tell me, what is the main differences between associative array and Nested table. I'm not sure, in this case we are to use.

    Did you happen to read the documentation, explain its good enough!
    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/composites.htm#LNPLS005

    Aman...

  • Check if a value is in an associative array?

    Hello
    I am writing a process to plug into an existing infrastructure. I have an associative array of data (that I can't change the definition of) which is defined as:
    type vc_arr2 is table of the varchar2 (32767) index directory.

    An example of a data set can be:
    Key   Text
    1 => Apple
    2 => Banana
    3 => Pear
    4 => Plum
    5 => Grape
    etc etc
    Now I need to be able to see information indicating if a specific text value appears in the values, that is to say "is"Bananas"in the table? Now of course I could do it by writing a procedure loop over all the elements in order but there at - it do something built that? There are the obvious overhead (potentially) to loop through each element for each item, I'm looking for - I hope that there is something built in which more effective (IE, 'index' values or something like that).
    As far as I know, ARRAY. Exists() works on the key and not the value, and MEMBER OF cannot be used with associative arrays.
    I'm not interested in what the key is for a given value (and I realize, it may be more than one key mapping to a given value), all I want is just if the element exists in the table.

    Any help or suggestions would be greatly appreciated!

    No, you will need to loop through each of them, as your index finger is not on the text.

    No reason to use an associative array in the first place? Why not use database and SQL tables? Oracle is good at those. ;)

  • Associative arrays... items in the index

    I can control the index of an associative array like that...
     TYPE aat_id IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
      aa_ids aat_id;
    
    BEGIN
    
         aa_ids(1) := 3;
         aa_ids(2) := 8;
         aa_ids(2) := 10;
         
    aa_ids.delete(2);
    
    dbms_output.put_line(aa_ids.count);
    
    END;
    How can I control the index in the statement of collection in bulk as follows... so that I can delete records using this index
     SELECT decode(mod(rownum,2),1,1,2), object_name BULK COLLECT INTO aa_recs
         FROM   all_objects WHERE  ROWNUM <= 6;
    Thank you
    HESH.

    HESH wrote:

    but I have to play with the collected values, I want to delete the values in bulk without a loop through the list there at - it a trick possible to do this?

    Using not PL/SQL and bays of PL/SQL at all - just using simple native SQL.

    Before bulk collection and construction of an associative array, for the use of the values in table for future SQL operations, I rather to store the collection of values in a TWG (global temporary table) instead. A TWG can be indexed - and can thus provide much better access to the data as an associative array. He played better. It can be used via SQL, native mode.

    The best place for the data is in the database. Not in the PL/SQL layer. This means that in SQL tables and not in PL/SQL tables or collections.

    There are very few situations in PL/SQL, which require the use of associative arrays. If few, the majority of the PL/SQL code using associative arrays, IMO do badly. And what you've posted so far, I do not see a specific requirement for associative arrays.

    So be sure you use the correct feature - and make sure that it is also well put to use in your code.

    PS. HESH is a strange name. I'm used to HESH meaning High Explosive Squash Head (used for the filming of shielding). :-)

  • What is the difference between associative arrays and nested tables?

    Hello
    What is the difference between associative arrays and nested tables?

    nested tables cannot be indexed by other than pls_integer and unlike nested tables table associative cananot be declared at the schema level.

    is there any other difference set apart from the diff above 2?

    user13710379 wrote:
    What is the difference between associative arrays and nested tables?

    Name-value pairs (associative) against a list of values (table standard/nested table).

    nested tables cannot be indexed by other than pls_integer

    They are not "indexed" the way in which an associative array is indexed. A standard table is referenced by the position of the cell in the table. This position is essentially the offset of the memory of the cell from the start address of the table.

    Can not solve a cell in an associative array directly via a memory offset index. You place a cell reference value it by his 'name' (a search in the linked list/hash table).

    The following example shows the difference between the pairs of name / value and a list of core values.

    SQL> declare
      2          --// associative arrays are NAME-VALUE pairs
      3          type TArr1 is table of varchar2(10) index by pls_integer;
      4          type TArr2 is table of varchar2(10) index by varchar2(10);
      5
      6          arr1    TArr1;
      7          arr2    TArr2;
      8  begin
      9          arr1(100) := '1st entry';
     10          arr1(1) := '2nd entry';
     11          arr1(5) := '3rd entry';
     12
     13          arr2('john') := 'New York';
     14          arr2('jane') := 'Paris';
     15          arr2('jack') := 'London';
     16
     17  end;
     18  /
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL>
    SQL> declare
      2          --// standard arrays are lists
      3          type TArr3 is table of varchar2(10);
      4          type TArr4 is table of number;
      5
      6          arr3    TArr3;
      7          arr4    TArr4;
      8  begin
      9          arr3 := new TArr3( '1st entry', '2nd entry', '3rd entry' );
     10
     11          arr4 := new TArr4( 100, 1, 5 );
     12  end;
     13  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • 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.

Maybe you are looking for