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. ;)

Tags: Database

Similar Questions

  • How to check if a value exists in a column

    Hello Experts,

    version: 10.1.0.5

    I am a novice in pl/sql programming. I am trying to create a procedure that checks if a value exists in a column and if it is not it inserts. Here's the procedure and errors,

    SQL > CREATE OR REPLACE PACKAGE BODY manr.audit_pkg

    2 PROCEDURE audit_proc (number of p_sessionid, p_username VARCHAR2, date of the p_date) IS

    3 BEGIN

    4 If p_sessionid not in (select manr.audit_history sessionid)

    5. can

    6 INSERT INTO manr.audit_history VALUES (p_sessionid, p_username, p_date);

    7 validation;

    8 end if;

    9 END;

    10 END audit_pkg;

    11.

    WARNING: The body of a Package created with compilation errors.

    SQL > show error

    PACKAGE BODY HÉLÈNE errors. AUDIT_PKG:

    LINE/COL ERROR

    -------- -----------------------------------------------------------------

    4/1 PL/SQL: statement ignored

    4/22 PLS-00405: subquery not allowed in this context

    Could you please tell me where I'm wrong. Thanks for your help.

    Rocky

    Hello

    If p_sessionid not in (select manr.audit_history sessionid)

    Try:

    .....

    Select count (*) in the v_sessionid of manr.audit_history

    where sessionid = p_sessionid;

    If v_sessionid > 0 then

    .....

    on the other

    ....

    end if;

    Ziut

  • Checking the negative value

    Hey guys I have a result on the ground which is of type varchar, but it stores numbers. I want to check if the value is negative or not. The code below works perfectly except for 1 case where the result has only ' - '. -indicates a missing value not a negative... How this can be fixed. Here is my code snippet.
    -Search for numeric values
    IF (trim (TRANSLATE (resvalue,'+ -. 0123456789', ' ')) IS NULL) THEN
    -Look for the negative value if the value is numeric
    IF (substr (resvalue, 1, 1) = '-' AND substr (resvalue, 0, 1) is not null) THEN
    v_ret_msg: = v_result_name | "" A negative result. "

    Also check the LENGTH of resvalue.
    That is to say:
    If length (resvalue) = 1 and substr (resvalue, 1, 1) = '-' then...

  • An associative array in PL/SQL: key = varchar2, value = varray (varchar2)

    I'm doing an associative array, where the key is a string and the value is an array of strings.

    I tried to declare it like this:

    PROCEDURE myProcedure IS
    tableau_donnees argument type is varray (200) of VARCHAR2 (20);
    Column TYPE IS an ARRAY OF tableau_donnees INDEX BY VARCHAR2 (20);
    my_collection columns; -collection of multi dimensional pl/sql
    BEGIN
    my_collection ('test') (1): = "Hello"; -It is the idea...
    "my_collection ('test') (2): = ' 8128 is the number";
    my_collection ("some other field' ') (1): = 'foo';
    -etc etc.

    But I get the error Oracle ORA-06531, reference to an uninitialized collection:

    Cause: A service of element or member of a nested table or varray has been referenced (where an initialized collection is necessary) without the collection has been initialized.

    Action: Initialize the collection with an appropriate constructor or assignment of the whole object.

    I tried to use 'extend()' initialize the varray, but no help...
    my_collection('test').extend (200);

    -----
    I also tried this:

    PROCEDURE myProcedure IS
    Data TYPE of TABLE IS OF VARCHAR2 (20);
    Column TYPE IS an ARRAY OF data INDEX BY VARCHAR2 (20);
    my_collection columns; -collection of multi dimensional pl/sql


    But it's always the same. I am quite new to PL/SQL, if any help would be great!


    -j

    900685 wrote:
    I'm doing an associative array, where the key is a string and the value is an array of strings.

    create or replace
      procedure myProcedure
        is
            type data_array
              is
                varray(200) of varchar2(20);
            type coltype
              is
                table of data_array
                index by varchar2(20);
            my_collection coltype;
        begin
            my_collection('test') := data_array('hello','8128 is the number');
            my_collection('some other field') := data_array('foo');
    end;
    /
    

    And if you want to add elements in varray:

    create or replace
      procedure myProcedure
        is
            type data_array
              is
                varray(200) of varchar2(20);
            type coltype
              is
                table of data_array
                index by varchar2(20);
            my_collection coltype;
        begin
            my_collection('test') := data_array('hello');
            my_collection('test').extend;
            my_collection('test')(2) := '8128 is the number';
            my_collection('some other field') := data_array('foo');
    end;
    /
    

    Or:

    create or replace
      procedure myProcedure
        is
            type data_array
              is
                varray(200) of varchar2(20);
            type coltype
              is
                table of data_array
                index by varchar2(20);
            my_collection coltype;
        begin
            my_collection('test') := data_array(); -- initialize
            my_collection('test').extend;
            my_collection('test')(1) := 'hello';
            my_collection('test').extend;
            my_collection('test')(2) := '8128 is the number';
            my_collection('some other field') := data_array('foo');
    end;
    /
    

    SY.

  • Customize alert messages to check the duplicate value and alert success

    Hi all

    I want to show two alert against the button 'Submit' even at -.

    1 the attention of messages to check the duplicate value and show the duplicate value found alert and
    2 alert if successful the form's success to commit no duplicate values found.

    I did all the thing but what alert-1 show and I pressed the ok button of the alert, then the second alert also shows that I don't want to show.

    Who can I do about it? Have someone to help me!

    Arif

    Use the folliwng in PRE-INSERT-TRIGGER.

    There is not a lot of changes with the exception

    where CANCELLATION_USERID =: CANCELLATION_USERID;

    and

    If valExists > 0 then

    declare
    
     valExists number;
    
    begin
    
     select count(*) into valExists
     from USERDELETION
     where CANCELLATION_USERID = to_char(:CANCELLATION_USERID);
    
     if valExists > 0 then
      message('Duplicate value found !');
      -- show_alert('ERROR_ALERT');
     else
      message('All is well');
      -- show_alert('All is well ');
     end if;
    
    end;
    
  • How to check if the value is NULL in the script

    Please, tell which function should I use to check if the value is NULL
    as: If some_member = NULL then...

    Thank you very much

    If you mean #missing:

    Commission (IF (sales <> #MISSING))
    Commission = sales *. 1;
    Another Commission = #MISSING;
    ENDIF ;);

    This example is from the SER60

    PLEASE NOTE: For some reason, the not equals sign does not appear on the first line of the IF statement. (i.e. IF (SALES does not #MISSING))

  • 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');

  • Associative array in Oracle procedure problem

    Hello

    I searched through the internet and this forum and have not been able to solve a problem using the associative array of values in an IN clause. Everything I read says that I can not use the associative array directly in the SQL statement. I have to convert it to a table and then I can use it. Unfortunately, I get a ' ORA-21700: object does not exist or is marked for deletion "error when trying to access the table, I filled the table. Please note that I checked the table is actually filled during the loop. I capture the error when you are referencing in the SELECT statement.

    I stated the following in the ARCHIVE package specification:

    TYPE RSType IS REF CURSOR;
    TYPE integer_aat IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
    Integer_table TYPE TABLE IS OF INTEGER;


    The procedure is the following:

    PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
    v_categories IN ARCHIVE.integer_aat,
    RS ON RSType)
    AS
    / * END: Returns the results for the category and key word provided
    VARIABLES:
    v_categories = array of categories of documents
    v_term = keyword entered
    RS = game results
    */
    tbl_cat ARCHIVE.integer_table: = ARCHIVE.integer_table ();

    BEGIN

    BECAUSE me in 1... v_categories. COUNTY
    LOOP
    tbl_cat. EXTEND (1);
    tbl_cat (i): = v_categories (i);
    END LOOP;

    OPEN FOR RS
    SELECT A.ID,
    B.CATEGORY,
    A.FILENAME,
    A.DISPLAY_NAME,
    A.COMMENTS
    OF TBL_ARCHIVE_DOCUMENTS,.
    B TBL_ARCHIVE_DOC_CAT,
    C TBL_ARCHIVE_DOC_KEYWORDS
    WHERE A.ID = B.ID
    AND A.ID = C.ID
    AND B.CATEGORY in (SELECT * FROM TABLE (tbl_cat))
    AND C.KEYWORD = v_term
    ORDER BY A.ID;
    END SEL_SEARCH_RESULTS;

    Any help would be greatly appreciated and thanks in advance.

    Matt

    905707 wrote:
    Thanks for the quick response. I looked at the example suggest you and made the following changes. Now, I get an invalid 'Data Type' error on the "column_value SELECT FROM TABLE (CAST (tbl_cat AS tbl_integer))' statement. I must be missing something simple and I can't put my finger on it.

    You did not create a SQL type as I said. tbl_integer is still declared in the PLSQL code you have posted.

    Reread my initial response and look at the example I posted (the very first thing that is done is to create a SQL type).

  • 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

  • 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

  • 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

  • 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.

  • 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> 
    

Maybe you are looking for