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

Tags: Database

Similar Questions

  • 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

  • How to share an associative array throughout the entire instance?

    Hi all

    I have an associative array containing a lot of data and it would barely change, I want to keep in memory and share all throughout the entirety of an instance and make sure that all the sessions for all users, get the same table associative, is - it possible?

    Thanks in advance.

    >

    I just want to keep it in memory and share them throughout the entire instance and make sure that all sessions of all users get the same associative array, is it possible?

    Why do you want to keep in mind?
    Will using a table for it, who has access frequently, almost will always be in the buffer cache, performance of the cause of the problems for you?

    The only other way to keep the data in memory in the world FLEURIDAS to all database sessions is to use the global application context functionality. With which you can store [name, value] pairs in memory and easily (read) access using integrated SYS_CONTEXT.

    Toon

  • Use an associative array with the paragraph

    Hello
    I'm trying to do something like this:

    declare
    l_items parse_pkg.items_tt;
    Enter numbers are the number table.
    n numbers;
    org varchar2 (100): = 1 | 2. 3. 4';
    Start
    l_items: = string_to_list (org); -string_to_list is Steve Feuerstein function that returns a table of varchar2s, items_tt
    Select to bulk org fired n of org_table
    where org table (l_items);
    end;

    This seems like it should work when I look at http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:210612357425
    I'm sure that someone understands what I'm trying to do and can point me to the light.
    Thank you!

    user12020272 wrote:
    Thanks much for the reply. I'm trying to understand your first point.

    All my 'points' are for the second part, which executes the SQL statement. I'll give you a simplified example:

    SQL> declare
      2      type items_tt is table of varchar2(10);
      3      l_items items_tt := items_tt('KING','ALLEN');
      4      type numbers is table of number;
      5      n numbers;
      6  begin
      7      select  sal
      8        bulk collect
      9        into n
     10        from emp
     11        where ename in l_items;
     12  end;
     13  /
          where ename in l_items;
                         *
    ERROR at line 11:
    ORA-06550: line 11, column 22:
    PLS-00642: local collection types not allowed in SQL statements
    
    SQL> 
    

    Now create type items_tt in SQL:

    SQL> declare
      2      l_items items_tt := items_tt('KING','ALLEN');
      3      type numbers is table of number;
      4      n numbers;
      5  begin
      6      select  sal
      7        bulk collect
      8        into n
      9        from emp
     10        where ename in l_items;
     11  end;
     12  /
          where ename in l_items;
                         *
    ERROR at line 10:
    ORA-06550: line 10, column 22:
    PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got SCOTT.ITEMS_TT
    ORA-06550: line 6, column 5:
    PL/SQL: SQL Statement ignored
    
    SQL> 
    

    So, we went first issue. Now my second point:

    SQL> declare
      2      l_items items_tt := items_tt('KING','ALLEN');
      3      type numbers is table of number;
      4      n numbers;
      5  begin
      6      select  sal
      7        bulk collect
      8        into n
      9        from emp
     10        where ename member of l_items;
     11  end;
     12  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    As I already mentioned, this also works:

    SQL> declare
      2      l_items items_tt := items_tt('KING','ALLEN');
      3      type numbers is table of number;
      4      n numbers;
      5  begin
      6      select  sal
      7        bulk collect
      8        into n
      9        from emp
     10        where ename in (select * from table(l_items));
     11  end;
     12  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Automatic indexation 2D array in the loop For - what is happening?

    I found many sources dealing 1 d tables in a loop For or a While loop, using automatic indexing, but nothing on the tables of higher order.

    I work with a program that feeds a 2D array in a loop (see table).  From what I see, it looks like this the results of automatic indexing in a 1 d, the first column of table 2-D table.

    This is the expected behavior, and it would hold true for arrays of higher order, table 3D for example?

    Is it possible to refer to the second column rather than the first?

    wildcatherder wrote:

    I found many sources dealing 1 d tables in a loop For or a While loop, using automatic indexing, but nothing on the tables of higher order.

    I work with a program that feeds a 2D array in a loop (see table).  From what I see, it looks like this the results of automatic indexing in a 1 d, the first column of table 2-D table.

    N ° it auto-index through a line at a time table.  You will get a 1 d table which consists of all of the columns that make up each row in each iteration.

    This is the expected behavior, and it would hold true for arrays of higher order, table 3D for example?

    Yes.  Automatic indexing on a 3D Board will give you a table on each iteration of each page 2D.

    Is it possible to refer to the second column rather than the first?  This question applies once you understand the first response.

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

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

  • Use FOR... LOOP counter in the treatment of PL/SQL procedures with nest. Table

    Hi all!
    I learn PL/SQL on the book by Steve Bobrovsky (specified below, sample comes from it) and I have a question.

    In the procedure of the below specified program used a currentElement integer variable to get the reference to the line in the nested table of data type % ROWTYPE.
    Meanwhile, the program itself uses a common FOR... LOOP counter I have.
    DECLARE
     TYPE partsTable IS TABLE OF parts%ROWTYPE;
     tempParts partsTable := partsTable();
     CURSOR selectedParts IS 
      SELECT * FROM parts ORDER BY id;
     currentPart selectedParts%ROWTYPE;
     currentElement INTEGER;
     PROCEDURE printParts(p_title IN VARCHAR2, p_collection IN partsTable) IS
      BEGIN
       DBMS_OUTPUT.PUT_LINE(' ');
       DBMS_OUTPUT.PUT_LINE(p_title || ' elements: ' || p_collection.COUNT);
       currentElement := p_collection.FIRST;
       FOR i IN 1 .. p_collection.COUNT
       LOOP
        DBMS_OUTPUT.PUT('Element #' || currentElement || ' is ');
         IF tempParts(currentElement).id IS NULL THEN DBMS_OUTPUT.PUT_LINE('an empty element.');
         ELSE DBMS_OUTPUT.PUT_LINE('ID: ' || tempParts(currentElement).id || ' DESCRIPTION: ' || tempParts(currentElement).description);
         END IF;
        currentElement := p_collection.NEXT(currentElement);
       END LOOP;
     END printParts;
    BEGIN
     FOR currentPart IN selectedParts
     LOOP
      tempParts.EXTEND(2);
      tempParts(tempParts.LAST) := currentPart;
     END LOOP;
     printParts('Densely populated', tempParts);
     FOR i IN 1 .. tempParts.COUNT
     LOOP
      IF tempParts(i).id is NULL THEN tempParts.DELETE(i);
      END IF;
     END LOOP;
     FOR i IN 1 .. 50
     LOOP
      DBMS_OUTPUT.PUT('-');
     END LOOP;
     printParts('Sparsely populated', tempParts);
    END;
    /
    When I substituted a global variable of INTEGER type such for... The LOOP counter, an APEX have returned an error "ORA-01403: no data found.
    DECLARE
     TYPE partsTable IS TABLE OF parts%ROWTYPE;
     tempParts partsTable := partsTable();
     CURSOR selectedParts IS 
      SELECT * FROM parts ORDER BY id;
     currentPart selectedParts%ROWTYPE;
     PROCEDURE printParts(p_title IN VARCHAR2, p_collection IN partsTable) IS
      BEGIN
       DBMS_OUTPUT.PUT_LINE(' ');
       DBMS_OUTPUT.PUT_LINE(p_title || ' elements: ' || p_collection.COUNT);
       FOR i IN 1 .. p_collection.COUNT
       LOOP
        DBMS_OUTPUT.PUT('Element is ');
         IF tempParts(i).id IS NULL THEN DBMS_OUTPUT.PUT_LINE('an empty element.');
         ELSE DBMS_OUTPUT.PUT_LINE('ID: ' || tempParts(i).id || ' DESCRIPTION: ' || tempParts(i).description);
         END IF;
       END LOOP;
     END printParts;
    BEGIN
     FOR currentPart IN selectedParts
     LOOP
      tempParts.EXTEND(2);
      tempParts(tempParts.LAST) := currentPart;
     END LOOP;
     printParts('Densely populated', tempParts);
     FOR i IN 1 .. tempParts.COUNT
     LOOP
      IF tempParts(i).id is NULL THEN tempParts.DELETE(i);
      END IF;
     END LOOP;
     FOR i IN 1 .. 50
     LOOP
      DBMS_OUTPUT.PUT('-');
     END LOOP;
     printParts('Sparsely populated', tempParts);
    END;
    /
    When I tried to manage this code in SQL * Plus, the following picture emerged:
    Densely populated elements: 10
    Element is an empty element.
    Element is ID: 1 DESCRIPTION: Fax Machine
    Element is an empty element.
    Element is ID: 2 DESCRIPTION: Copy Machine
    Element is an empty element.
    Element is ID: 3 DESCRIPTION: Laptop PC
    Element is an empty element.
    Element is ID: 4 DESCRIPTION: Desktop PC
    Element is an empty element.
    Element is ID: 5 DESCRIPTION: Scanner
    --------------------------------------------------
    Sparsely populated elements: 5
    DECLARE
    *                                                 
    ERROR at line 1:                                  
    ORA-01403: no data found                          
    ORA-06512: at line 14                             
    ORA-06512: at line 35
    What's not in the code (or what I did not understand)? Help please!

    Your error occurs because you are dealing with a sparsely populated collection and using an index for items that do not exist.

    For collections of the low density of population, you must iterate through using FIRST and THEN as modeled not from 1 to COUNT.

    The crucial difference between your code and the example is:

    tempParts(i)
    

    Which, as you have demonstrated, doesn't work very well (!) if there is no item (i).

    The code example is a little unusual in my opinion.

       currentElement := p_collection.FIRST;
       FOR i IN 1 .. p_collection.COUNT
       LOOP
        ...
        currentElement := p_collection.NEXT(currentElement);
       END LOOP;
    

    It works, but it's an unusual way to iterate through a collection of rare which is perhaps most often done like this:

       currentElement := p_collection.FIRST;
       WHILE(currentElement IS NOT NULL)
       LOOP
        ...
        currentElement := p_collection.NEXT(currentElement);
       END LOOP;
    

    Which is perhaps less open to confusion.

    In the end, the distinction between

    tempParts(currentElement).id
    

    and

    tempParts(i).id
    

    is crucial.

  • Proc 10 call Oracle stored g with associative array from c# VS 2008

    I have the following PL/SQL procedure:


    CREATE OR REPLACE PROCEDURE HMA_ADM. PRC_VDM_SAVDEL_VEN_DOC

    (

    P_OP IN VARCHAR2,

    P_USRID IN TB_VDM_MANAGE_DOCUMENTS. CREATEDBY % TYPE,

    P_DATE IN VARCHAR2,--MUST BE STRING, OTHERWISE WE GET AN ERROR

    P_DOCNAM IN TB_VDM_MANAGE_DOCUMENTS. DOCUMENTNAME % TYPE,

    P_DOCLNK IN TB_VDM_MANAGE_DOCUMENTS. BUILDER % TYPE.

    P_FNGUID IN TB_VDM_MANAGE_DOCUMENTS. FILENET_GUID % TYPE,

    P_DESC IN TB_VDM_MANAGE_DOCUMENTS. DESCRIPTION % TYPE,

    P_REQID IN VARR

    ) IS


    Where VARR is:


    CREATE OR REPLACE TYPE VARR'S ARRAY OF INTEGER;


    In c#, I have the following code:

    Int64 [] intReqID;



    OracleCommand cmdVDL = new OracleCommand (DBQueries.SPQRY_SAVDELVENDOC, connDB);



    cmdVDL.CommandType = CommandType.StoredProcedure;


    cmdVDL.Parameters.Add (new OracleParameter ("P_OP", strop));

    cmdVDL.Parameters.Add (new OracleParameter ("P_CREATEBY", strUID));

    cmdVDL.Parameters.Add (new OracleParameter ("P_CREATEDATE", strDate));

    cmdVDL.Parameters.Add (new OracleParameter ("P_DOCNAM", strDocNam));

    cmdVDL.Parameters.Add (new OracleParameter ("P_DOCLNK", strURL));

    cmdVDL.Parameters.Add (new OracleParameter ("P_FNGUID", strGUID));

    cmdVDL.Parameters.Add (new OracleParameter ("P_DESC", strDesc));

    cmdVDL.Parameters.Add (new OracleParameter ("P_REQID", OracleDbType.Int64) {}

    CollectionType = OracleCollectionType.PLSQLAssociativeArray,

    Size = intReqID.Count (),

    Value = intReqID,

    DbType = DbType.Int64,

    OracleDbType = OracleDbType.Int64

    });



    [] OracleParameterStatus stat = new OracleParameterStatus [intReqID.Count ()];


    for (i = 0; i < intReqID.Count (); i ++) {}

    STAT [i] = OracleParameterStatus.Success;

    }


    "" "cmdVDL.Parameters ["P_REQID"]." ArrayBindStatus = stat;


    cmdVDL.ExecuteNonQuery ();

    When I run the present, I get the following error:

    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in the call to 'PRC_VDM_SAVDEL_VEN_DOC '.
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored

    If I remove the associative array at the same time, the procedure works very well.

    What I am doing wrong?

    In addition,

    (1) support UDT requires ODP 11106.20 or later version (but can be used against db 10 g)
    (2) if the plsql is editable, you can exchange to an associative array rather to avoid having to create classes customized for the UDT and here is a short example of soft.
    Greg

    /*
    CREATE or replace PACKAGE MYPACK3 AS
    TYPE numarray is table of number index by BINARY_INTEGER;
    PROCEDURE getempsinarray(thearray IN numarray, numrecs out number);
    END MYPACK3;
    /
    CREATE or replace PACKAGE BODY MYPACK3 AS
     PROCEDURE getempsinarray(thearray IN numarray, numrecs out number)
     IS
     begin
      numrecs :=  thearray.count;
     END getempsinarray;
    END MYPACK3;
    /
    */
    
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    
    public class indexby
    {
         public static void Main()
         {
          OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger;");
          con.Open();
          OracleCommand cmd = new OracleCommand("mypack3.getempsinarray", con);
          cmd.CommandType = CommandType.StoredProcedure;
    
          OracleParameter Param1 = cmd.Parameters.Add("param1", OracleDbType.Int32);
          Param1.Direction = ParameterDirection.Input;
          Param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
          Param1.Value = new int[3]{7369,7499, 7521};
          Param1.Size = 3;
    
          OracleParameter Param2 = cmd.Parameters.Add("param2", OracleDbType.Int32, DBNull.Value, ParameterDirection.Output );
    
         cmd.ExecuteNonQuery();
         Console.WriteLine("{0} records passed in",Param2.Value);
          con.Close();
         }
    }
    
  • Re: creating dynamic associative arrays

    Hi, I need some advice on the following problem. I develop code that allows me to copy & paste a spreadsheet into a TextArea and parse text pasted to dynamically generate a DataGrid control. I assume that the first line of text contains the headers of each column, parse the line and dynamically generate the columns to the DataGrid control. Now I need a way to generate each Clotilde the DataGrid from the rest of the lines. The question that I'm struggling with (new Flex) is. I think I need to create an associative array of the form:

    var asArray:Object = {col1: 'value1', col2: "Value2", etc.}

    The problem is that all the column names in a table and each value is stored in another table. How to dynamically create a construction which will be

    take me to represent a row in a DataGrid as described in EnTableau? In other words, is there a way to dynamically generate a statement like the one above?

    Grateful for your help!

    Ko

    If I understand correctly, you are able to analyze all your data to two types of arrays:

    var table: columns = {"column1", "column2",...}

    var rowValues:Array = {, ",...}

    So as you can see I guess that each value in rowValues table has light-emitting column name in the columns table. So you can build your 'associative' (in fact it is just a simple object) like this:

    var rowObject:Object = new Object();

    for (var i: int = 0; i< rowvalues.length;="" i++)="">

    rowObject [GBA [i]] = rowValues [i];

    }

    The heart of the loop is the third line and the use of hooks on an object.

  • Associative array declaration Inline?

    I would like to declare an associative array with the keys based on the constants using the method inline.

    The documentation shows inline declarations of associative array as follows:

    var assocArray:Array = {key: "value", key2: "Value2", key3: "Value3"};

    the problem here is that the following does not work:

    var assocArray:Array = {this.const1: "value", this.const2: "value2", this.const3: "value3"};

    To work around this problem, I had to do the following so far:

    var assocArray:Array = new Array();

    assocArray [this.const1] = 'value ';

    assocArray [this.const2] = 'value2 ';

    assocArray [this.const3] = "Value3";

    How can this be done online?

    It cannot be done online.

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

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

  • [JS] Adding methods to associative arrays

    I have an associative array. I want to add a method that returns an array of all the names of the associative array. The problem is that it returns the name of the method, too. Is it all so he can only return the property names and not the methods? In the code below, I would like to myEveryItem item to return a table of two, not three.

    RangePresets = {};
    RangePresets.everyItem = getEveryItem;
    RangePresets["[Default]"] = new RangePreset(578,800);
    RangePresets["Daily Dose"] = new RangePreset(360, 600);
    myEveryItem = RangePresets.everyItem();
    
    // RangePreset Constructor
    function RangePreset(hr,vr){
         this.horizontalRange = hr;
         this.verticalRange = vr;
    }
    
    
    function getEveryItem(){
         var ei = [];
         for (x in this)
         ei.push(x);
         return ei;
    }
     
    

    You can use Object.reflect.properties, but which will give you proto, County, classand take into account outside your own properties.

    You can also test: if (object [x].constructor.name == "Function") to exclude functions.

    Substances

Maybe you are looking for