REF CURSOR to Associative Array

I have a procedure that builds up a collection (associative array / index-by table). Is there any way to hand the collection over to ODP.NET without putting the contents into a temporary table? REF CURSOR seems to fit, but I cannot find the syntax to OPEN a REF CURSOR for the collection.
I am trying to turn the GetResourceGroup() a_Resources parameter into a ref cursor in the example below (which, as I understand it, would also hold the collection in memory until the cursor is closed).
Alternatively, is there a direct method? I.e. is it possible to get the collection directly into a DataTable or similar?
Any advice gratefully received,
Peter
TYPE RsrcRow IS RECORD
ResourceId Resource.ResourceId%TYPE,
ResourceName Resource.ResourceName%TYPE
TYPE Resources IS TABLE OF RsrcRow INDEX BY VARCHAR2(80);
PROCEDURE GetResourceGroup(
a_ResourceType IN VARCHAR2,
a_Resources OUT Resources
IS
l_LocalCollection Resources;
BEGIN
GetResourcesByType(a_ResourceType, l_LocalCollection);
-- Return resource set (need to port this to ODP.NET).
a_Resources := l_LocalCollection;
RETURN;
END GetResourceGroup;

odp.net does not have collection support right now.
PL/SQL Associative Array should be available in next release (see other forum threads)
1. Support for Varchar2 indexes is unlikely (since OCI does not provide such functionality). Which means you can only return an C style "array" like structure at best.
2. Your 'GetResourceGroup' need to return REF CURSOR (or other primitive type like VARCHAR2), until Associative Array become available.
FB

Similar Messages

  • Array/ In Ref cursor

    Hi all,
    I need to create a stored procedure which takes 30 arguments. However specifying them will become very messy. Is there a shorter way to pass in so many arguments? Perhaps an In Ref Cursor or an array?
    Any help would be much appreciated.
    Thanks
    Rich

    > Is there a shorter way to pass in so many arguments?
    Yes. You can define a PL/SQL record structure (like a C struct). And if I'm not mistaken (last used Pro*C in '99), you can actually define a C struct wrapper for a PL/SQL struct in Pro*C.
    Another option is defining an ADT (Advance Data Type). Superior to a PL/SQL struct as this is usable in both SQL and PL/SQL engines, is object orientated and therefore support subclassing, methods and so on.
    Slightly more complex to use from Pro*C perhaps? I know the OCI supported an "object" interface for ADT's since Oracle 8i, but have never used it myself.
    > Perhaps an In Ref Cursor or an array?
    Not sure how a ref cursor can be used to pass parameter values.. A ref cursor is pointer to a SQL cursor in the Shared Pool - which can be passed to an external client (like Pro*C program) to use.
    An array is also an option. Oracle uses it themselves for the two parameter calling method for mod_plsql (Oracle Web Cartridge). Your PL/SQL web enabled proc is called with a name list and a value list array.

  • Bulk collect into associative array

    Please advise examples of a bulkk collecting a cursor into associative array amd working on the basis of one column as key.
    Here need to calculate based onnfollowing data and key as Col1 until all records for that key are worked upon.
    Col1 col2 col3 Flag
    AA A11 A13 1
    AA A12 A13 1
    BB B11 B11 1
    BB B11 B11 2
    CC C11 C11 1

    ?:|
    You might want to rephrase your question...
    http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    Examples:
    http://www.java2s.com/Code/Oracle/PL-SQL/Howtodoabulkcollectintoanassociativearray.htm
    http://www.oracle-developer.net/display.php?id=201
    http://www.oracle.com/pls/db102/search?word=bulk+collect
    http://www.oracle.com/pls/db102/search?word=associative+array

  • Associative Array our only option?

    Hello,
    I'm having a problem accepting associative arrays as the only option I have for getting data from a stored procedure. I have a good reason for not wanting to use ref cursors as I am using the stored procedure to manipulate data which I in turn would like to pass back to VB through the stored procedure and would rather not have to insert he data into a table just to re-select it for a ref cursor.
    My main concern is that with associative arrays I am expected to define the number of return results before I even generate the data. Also from what I can see I am required to set the data length for each and every item in said array one at a time. All this overhead seems like more work than what I would have to do to utilizer a reference cursor. Is there a right way to do this? I would really like to do the most straight forward way I can without the extra processing.

    Hi,
    Here's a blog post of mine that illustrates using pipelined functions and PL/SQL to return results:
    http://oradim.blogspot.com/2007/10/odpnet-tip-using-pipelined-functions.html
    Not sure if that will be helpful in your case, but perhaps it might be a place to start anyway.
    - Mark

  • Associative Array error

    I am using a couple associative arrays in my code and comparing the data in one, and if it is an asterisk, I change it to use the data in the other. Here is the meat of my code. I am running into an error at the bolded line saying I have too many values, which I don't understand because the code is the exact same as the block of code right before it where I populate the first array. FYI, the table it is pulling from only has one row. The error is listed below the code.
    Code
    DECLARE
    TYPE refresh_file_t IS TABLE OF test.loading_dock%ROWTYPE ;
    refresh_data refresh_file_t ;
    prospect_data refresh_file_t ;
    TYPE CV_TYPE IS REF CURSOR ;
    c_id CV_TYPE ;
    v_id NUMBER(10) ;
    v_phone VARCHAR2(10) ;
    v_project VARCHAR2(10) ;
    BEGIN
    OPEN c_id FOR
    'SELECT id
    FROM test.loading_dock
    WHERE rownum = 1' ;
    LOOP
    FETCH c_id INTO v_id ;
    EXIT WHEN c_id%NOTFOUND ;
    SELECT * BULK COLLECT
    INTO refresh_data
    FROM test.loading_dock
    WHERE id = v_id ;
    SELECT * BULK COLLECT
    INTO prospect_data
    FROM test.prospects
    WHERE id_number = v_id ;
    IF refresh_data(1).home_phone = '*' THEN
    v_phone := prospect_data(1).phone ;
    ELSE
    v_phone := refresh_data(1).home_phone ;
    END IF ;
    DBMS_OUTPUT.PUT_LINE(v_phone) ;
    END LOOP ;
    CLOSE c_id ;
    END ;
    Error
    ORA-06550: line 29, column 13:
    PL/SQL: ORA-00913: too many values
    ORA-06550: line 27, column 13:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 34, column 46:
    PLS-00302: component 'PHONE' must be declared
    ORA-06550: line 34, column 13:
    PL/SQL: Statement ignored
    06550. 00000 - "line %s, column %s:\n%s"

    Collection prospect_data is of type refresh_file_t, which is a table of records of test.loading_dock%TYPE. Most likely tables test.loading_dock and test.prospects have different structure - test.prospects has fewer columns. So when you try to fetch from test.prospects into prospect_data you get the error Try replacing
    prospect_data refresh_file_t ;with
    TYPE prospect_data_t IS TABLE OF test.prospects%ROWTYPE ;
    prospect_data prospect_data_t ;SY.

  • Returning collection-associative array from pl-sql procedure

    CREATE OR REPLACE procedure test_ganesh( p_deptno IN number,gana out PARTIES_RESULT)
    is
    query varchar2(200);
    PARTY_ID varchar2(200);
    PARTY_CODE varchar2(200);
    PARTY_NAME varchar2(200);
    PARTY_SEQ VARCHAR2(200);
    counter number;
    TYPE PARTIES IS TABLE OF varchar2(2000) index by binary_integer;
    txn_parties PARTIES;
    type PARTIES_RESULT IS TABLE OF PARTIES index by binary_integer;
    total_result PARTIES_RESULT;
    TYPE EmpTyp IS REF CURSOR;
    p_du EmpTyp;
    p_cursor EmpTyp;
    global_counter number;
    begin
    global_counter:=1;
    counter:=1;
    open p_cursor FOR
    select A.ref_no
    from ot_lc_txn_details A
    where rownum <12;
    LOOP
    FETCH p_cursor INTO query;
    EXIT WHEN p_cursor%NOTFOUND;
    counter:=1;
    open p_du FOR
         select party_id,party_code,seq_no,party_name from ot_txn_party where ref_no=query;
         LOOP
         FETCH p_du INTO PARTY_ID,PARTY_CODE,PARTY_SEQ,PARTY_NAME;
         EXIT WHEN p_du%NOTFOUND;
         txn_parties(counter):=PARTY_ID || '&&&' || PARTY_CODE || '&&&'||PARTY_SEQ || '&&&' || PARTY_NAME;
              counter:=counter+1;
         END LOOP;
         CLOSE p_du;
    total_result(global_counter):=txn_parties;
    global_counter:=global_counter+1;
    END LOOP;
    CLOSE p_cursor;
    --open gana FOR SELECT * FROM table(cast(total_result as PARTIES_RESULT)) ;
    end;
    The error comes at line one, PLS-00905- object PARTIES_RESULT is invalid.
    i have used the create type thing to create this type.
    if i remove the out parameter it works, no compilation error.
    Questions i) How to return the associative array as out parameter?
    ii)Am i doing aynthing qrong here?
    iii) Can i open a ref cursor to this associative array and then return that ref_cursor?
    Please anyone reply back, Thanks in advance
    Message was edited by:
    user649602

    As an example:
    SQL> create type PARTIES is table of varchar2(2000);
      2  /
    Type created.
    SQL> create or replace procedure proc1(p_deptno number,gana out parties) as
      2  begin
      3   select ename
      4   bulk collect into gana
      5   from emp
      6   where deptno = p_deptno;
      7  end;
      8  /
    Procedure created.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Associative Array problem in Oracle Procedure

    Hi,
    I've searched through the internet and this forum and haven't been able to resolve a problem using associative array values within an IN clause. Everything I've read states that I can't 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'm receiving an "ORA-21700: object does not exist or is marked for delete" error when trying to access the table I've populated from the array. Please note that I have verified the table is actually being populated during the loop. I'm catching the error when referencing it in the SELECT statement.
    I've declared the following in the ARCHIVE package specification:
    TYPE RSType IS REF CURSOR;
    TYPE integer_aat IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
    TYPE integer_table IS TABLE OF INTEGER;
    The procedure is as follows:
    PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
    v_categories IN ARCHIVE.integer_aat,
    rs OUT RSType)
    AS
    /* PURPOSE: Return Search Results for the Category and Keyword Provided
    VARIABLES:
    v_categories = Document Categories array
    v_term = Keyword entered
    rs = Result Set
    tbl_cat ARCHIVE.integer_table := ARCHIVE.integer_table();
    BEGIN
    FOR i IN 1 .. v_categories.COUNT
    LOOP
    tbl_cat.EXTEND(1);
    tbl_cat(i) := v_categories(i);
    END LOOP;
    OPEN rs FOR
    SELECT A.ID,
    B.CATEGORY,
    A.FILENAME,
    A.DISPLAY_NAME,
    A.COMMENTS
    FROM TBL_ARCHIVE_DOCUMENTS A,
    TBL_ARCHIVE_DOC_CAT B,
    TBL_ARCHIVE_DOC_KEYWORDS C
    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

    Thank you for the quick response. I looked at the example you suggested and made the following changes. Now I'm receiving an "Invalid datatype" error on the "SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer))" statement. I must be missing something simple and I just can't put my finger on it.
    PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
    v_categories IN ARCHIVE.integer_aat,
    rs OUT RSType)
    AS
    /* PURPOSE: Return Search Results for the Category and Keyword Provided
    VARIABLES:
    v_categories = Document Categories array entered
    v_term = Keyword entered
    rs = Result Set
    TYPE tbl_integer IS TABLE OF INTEGER;
    tbl_cat tbl_integer;
    BEGIN
    FOR i IN 1 .. v_categories.COUNT
    LOOP
    tbl_cat.EXTEND(1);
    tbl_cat(i) := v_categories(i);
    END LOOP;
    OPEN rs FOR
    SELECT A.ID,
    B.CATEGORY,
    A.FILENAME,
    A.DISPLAY_NAME,
    A.COMMENTS
    FROM TBL_ARCHIVE_DOCUMENTS A,
    TBL_ARCHIVE_DOC_CAT B,
    TBL_ARCHIVE_DOC_KEYWORDS C
    WHERE A.ID = B.ID
    AND A.ID = C.ID
    AND B.CATEGORY IN (SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer)))
    AND C.KEYWORD = v_term
    ORDER BY A.ID;
    END SEL_SEARCH_RESULTS;

  • Passing Ref Cursor as IN parameter

    I have a situation where I have to send whole table into the stored procedure, I read from the oracle new feature for .Net documentation, It is possible to pass an ref cursor as IN parameter to an stored procedure. Please help me in this, it is urgent!
    I am using Visual Studio.Net 2003, ODP.Net.

    Array binding is the best method for large inserts from .NET.
    The problem with the associative array is:
    -you must write a PL/SQL procedure to actually do the inserts.
    -while this will get the data to the PL/SQL engine on the server in a block, it still must cross the into the SQL engine one row at at time.
    -Array binding is simpler (you use a normal insert).
    -There's a built-in knob to control the batch size.
    -The array of row data is copied all the way into the SQL engine together, so it's faster.
    Remember, array binding is how the SQL*Loader's conventional-path inserts work.
    According to Tom Kyte "you can achive 100's of rows per second into heavily indexed tables that are concurrently being read and updated by other processes."
    David

  • STORED PROCEDURE/REF CURSOR: How to output entire buffer

    I wrote a Stored Procedure wherein I use a Cursor to extract multiple
    rows and columns. I then write them into the buffer
    (dmbs_output.put_line). But when I try to capture the entire result
    into an OUT variable, I only get the last buffered line.
    So how do I output the entire buffer- all rows and columns? In other words (maybe), how do I use dbms_output.get_lines() to assign value to an OUT variable?
    Alternatively, using REF CURSOR as OUT variable, I added the following to "CREATE OR REPLACE PROCEDURE ... ()":
    cursor_out_test OUT cursor_test
    But when I tried:
    DEFINE CURSOR TYPE cursor_test IS REF CURSOR RETURN table%ROWTYPE;
    ...or...
    DECLARE TYPE cursor_test IS REF CURSOR RETURN table%ROWTYPE;
    I still got syntax errors.
    In one line, what I am trying to do is break the result array at the database level rather than at the application level.
    Cheers, Bill
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#LNPLS00605

    I did the following:
    OPEN CURSOR x
         LOOP
              FETCH CURSOR x INTO col1, col2
              (EXIT WHEN...)
              variable_line := col1 || col2
         END LOOP
    CLOSE CURSOR
    But after closing this cursor, variable_line contains only the last buffered line. I want all the looped lines (without using associative arrays, nested tables etc). So I guess I am just looking for some way to append data lines- adding chr(10) doesn't work either.
    Cheers, Bill

  • ORA-01008 with ref cursor and dynamic sql

    When I run the follwing procedure:
    variable x refcursor
    set autoprint on
    begin
      Crosstab.pivot(p_max_cols => 4,
       p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by job order by deptno) rn from scott.emp group by job, deptno',
       p_anchor => Crosstab.array('JOB'),
       p_pivot  => Crosstab.array('DEPTNO', 'CNT'),
       p_cursor => :x );
    end;I get the following error:
    ^----------------
    Statement Ignored
    set autoprint on
    begin
    adsmgr.Crosstab.pivot(p_max_cols => 4,
    p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by
    p_anchor => adsmgr.Crosstab.array('JOB'),
    p_pivot => adsmgr.Crosstab.array('DEPTNO', 'CNT'),
    p_cursor => :x );
    end;
    ORA-01008: not all variables bound
    I am running this on a stored procedure as follows:
    create or replace package Crosstab
    as
        type refcursor is ref cursor;
        type array is table of varchar2(30);
        procedure pivot( p_max_cols       in number   default null,
                         p_max_cols_query in varchar2 default null,
                         p_query          in varchar2,
                         p_anchor         in array,
                         p_pivot          in array,
                         p_cursor in out refcursor );
    end;
    create or replace package body Crosstab
    as
    procedure pivot( p_max_cols          in number   default null,
                     p_max_cols_query in varchar2 default null,
                     p_query          in varchar2,
                     p_anchor         in array,
                     p_pivot          in array,
                     p_cursor in out refcursor )
    as
        l_max_cols number;
        l_query    long;
        l_cnames   array;
    begin
        -- figure out the number of columns we must support
        -- we either KNOW this or we have a query that can tell us
        if ( p_max_cols is not null )
        then
            l_max_cols := p_max_cols;
        elsif ( p_max_cols_query is not null )
        then
            execute immediate p_max_cols_query into l_max_cols;
        else
            RAISE_APPLICATION_ERROR(-20001, 'Cannot figure out max cols');
        end if;
        -- Now, construct the query that can answer the question for us...
        -- start with the C1, C2, ... CX columns:
        l_query := 'select ';
        for i in 1 .. p_anchor.count
        loop
            l_query := l_query || p_anchor(i) || ',';
        end loop;
        -- Now add in the C{x+1}... CN columns to be pivoted:
        -- the format is "max(decode(rn,1,C{X+1},null)) cx+1_1"
        for i in 1 .. l_max_cols
        loop
            for j in 1 .. p_pivot.count
            loop
                l_query := l_query ||
                    'max(decode(rn,'||i||','||
                               p_pivot(j)||',null)) ' ||
                                p_pivot(j) || '_' || i || ',';
            end loop;
        end loop;
        -- Now just add in the original query
        l_query := rtrim(l_query,',')||' from ( '||p_query||') group by ';
        -- and then the group by columns...
        for i in 1 .. p_anchor.count
        loop
            l_query := l_query || p_anchor(i) || ',';
        end loop;
        l_query := rtrim(l_query,',');
        -- and return it
        execute immediate 'alter session set cursor_sharing=force';
        open p_cursor for l_query;
        execute immediate 'alter session set cursor_sharing=exact';
    end;
    end;
    /I can see from the error message that it is ignoring the x declaration, I assume it is because it does not recognise the type refcursor from the procedure.
    How do I get it to recognise this?
    Thank you in advance

    Thank you for your help
    This is the version of Oracle I am running, so this may have something to do with that.
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    I found this on Ask Tom (http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3027089372477)
    Hello, Tom.
    I have one bind variable in a dynamic SQL expression.
    When I open cursor for this sql, it gets me to ora-01008.
    Please consider:
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
    JServer Release 8.1.7.4.1 - Production
    SQL> declare
      2    type cur is ref cursor;
      3    res cur;
      4  begin
      5    open res for
      6    'select * from (select * from dual where :p = 1) connect by 1 = 1'
      7    using 1;
      8  end;
      9  /
    declare
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-06512: at line 5
    SQL> declare
      2    type cur is ref cursor;
      3    res cur;
      4  begin
      5    open res for
      6    'select * from (select * from dual where :p = 1) connect by 1 = 1'
      7    using 1, 2;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    And if I run the same thing on 10g -- all goes conversely. The first part runs ok, and the second
    part reports "ORA-01006: bind variable does not exist" (as it should be, I think). Remember, there
    is ONE bind variable in sql, not two. Is it a bug in 8i?
    What should we do to avoid this error running the same plsql program code on different Oracle
    versions?
    P.S. Thank you for your invaluable work on this site.
    Followup   June 9, 2005 - 6pm US/Eastern:
    what is the purpose of this query really?
    but it would appear to be a bug in 8i (since it should need but one).  You will have to work that
    via support. I changed the type to tarray to see if the reserved word was causing a problem.
    variable v_refcursor refcursor;
    set autoprint on;
    begin 
         crosstab.pivot (p_max_cols => 4,
                 p_query => 
                   'SELECT job, COUNT (*) cnt, deptno, ' || 
                   '       ROW_NUMBER () OVER ( ' || 
                   '          PARTITION BY job ' || 
                   '          ORDER BY deptno) rn ' || 
                   'FROM   emp ' ||
                   'GROUP BY job, deptno',
                   p_anchor => crosstab.tarray ('JOB'),
                   p_pivot => crosstab.tarray ('DEPTNO', 'CNT'),
                   p_cursor => :v_refcursor);
    end;
    /Was going to use this package as a stored procedure in forms but I not sure it's going to work now.

  • Associative Array vs Table Scan

    Still new to PL/SQL, but very keen to learn. I wondered if somebody could advise me whether I should use a collection (such as an associative array) instead of repeating a table scan within a loop for the example below. I need to read from an input table of experiment data and if the EXPERIMENT_ID does not already exist in my EXPERIMENTS table, then add it. Here is the code I have so far. My instinct is that it my code is inefficient. Would it be more efficient to scan the EXPERIMENTS table only once and store the list of IDs in a collection, then scan the collection within the loop?
    -- Create any new Experiment IDs if needed
    open CurExperiments;
    loop
    -- Fetch the explicit cursor
    fetch CurExperiments
    into vExpId, dExpDate;
    exit when CurExperiments%notfound;
    -- Check to see if already exists
    select count(id)
    into iCheckExpExists
    from experiments
    where id = vExpId;
    if iCheckExpExists = 0 then
    -- Experiment ID is not already in table so add a row
    insert into experiments
    (id, experiment_date)
    values(vExpId, dExpDate);
    end if;
    end loop;

    Except that rownum is assigned after the result set
    is computed, so the whole table will have to be
    scanned.really?
    SQL> explain plan for select * from i;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 1766854993
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |   910K|  4443K|   630   (3)| 00:00:08 |
    |   1 |  TABLE ACCESS FULL| I    |   910K|  4443K|   630   (3)| 00:00:08 |
    8 rows selected.
    SQL> explain plan for select * from i where rownum=1;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 2766403234
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |     5 |     2   (0)| 00:00:01 |
    |*  1 |  COUNT STOPKEY     |      |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| I    |     1 |     5 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM=1)
    14 rows selected.

  • Associative Array Assignment

    I have an associative array that is built on a record.
    TYPE LKey IS RECORD (
    lock_key locks.lock_key%TYPE,
    category_id_cd locks.category_id_cd%TYPE);
    TYPE LockKeys_t IS TABLE OF LKey
    INDEX BY PLS_INTEGER;
    v_LockKeys_arr LockKeys_t;
    How do I populate the elements of this array one row at a time within my cursor FOR loop? I just want to do something like this:
    SELECT v_lock_key, v_category_id_cd INTO v_LockKeys_arr FROM dual;
    When I try this I get : "expression v_LockKeys_arr in the INTO list is of wrong type."
    Then I will loop through the array and use each element one at a time:
    FOR j IN 1..v_LockKeys_arr.COUNT
    LOOP
    ReleaseLocks( v_LockKeys_arr(j).lock_key||'2:',
    v_Lockkeys_arr(j).category_id_cd,
    i_User, v_release_set );
    END LOOP;
    Thank you in advance for your time.

    DECLARE--CREATE RECORD
    TYPE CUSTOMER_RECORD IS RECORD (CUSTOMER_ACCT_ID NUMBER,
    CUSTOMER_NAME VARCHAR2(2000));
    --CREATE TABLE OF RECORD TYPE
    TYPE CUSTOMER_REC IS TABLE OF
    CUSTOMER_RECORD
    INDEX BY BINARY_INTEGER;
    --INSTANCE OF RECORD
    LREC_CUSTOMER_RECORD CUSTOMER_RECORD;
    --INSTANCE OF TABLE
    LT_CUSTOMER_REC CUSTOMER_REC;
    BEGIN
    --ASSIGN VALUES TO INSTANCE OF RECORD
    LREC_CUSTOMER_RECORD.CUSTOMER_ACCT_ID:=10;
    LREC_CUSTOMER_RECORD.CUSTOMER_NAME:='BHAGAT';
    --INSERT INTO TABLE, VALUES FROM RECORD INSTANCE
    LT_CUSTOMER_REC(1):=LREC_CUSTOMER_RECORD;
    --OUTPUT
    DBMS_OUTPUT.PUT_LINE(LT_CUSTOMER_REC(1).CUSTOMER_ACCT_ID);
    DBMS_OUTPUT.PUT_LINE(LT_CUSTOMER_REC(1).CUSTOMER_NAME);
    END;
    /

  • Associative Array with subsripts(Index) as Varchar2

    Hi All,     
    I m using Oracle Version 10.1.0.2.0 - Production     
    I have the following requirement:     
    The Associative array which holds the value with the subscripts(Index) as database table column.
    Create table Period_master
    Period_code_c Varchar2(10),
    Period_frm_dt Date,
    Period_to_dt Date,
    Year_code_c     Varchar2(10)
    Insert into period_master values ('10',to_date('01/01/2012','dd/mm/rrrr'),to_date('31/01/2012','dd/mm/rrrr'),'2011-2012');
    Insert into period_master Values ('11',to_date('01/02/2012','dd/mm/rrrr'),to_date('29/02/2012','dd/mm/rrrr'),'2011-2012');
    Insert into period_master Values ('12',to_date('01/03/2012','dd/mm/rrrr'),to_date('31/03/2012','dd/mm/rrrr'),'2011-2012');
    Insert into period_master Values ('13',to_date('01/04/2012','dd/mm/rrrr'),to_date('30/04/2012','dd/mm/rrrr'),'2012-2013');
    Insert into period_master Values ('14',to_date('01/05/2012','dd/mm/rrrr'),to_date('31/05/2012','dd/mm/rrrr'),'2012-2013');
    Commit;
    SQL > Select * from Period_Master;
    Period_code --- Period_frm_dt --- Period_to_dt ---- Year_code_c
    10     ---     01/01/2012 ---     31/01/2012     --- 2011-2012
    11     ---     01/02/2012 ---     29/02/2012     --- 2011-2012
    12     ---     01/03/2012 ---     31/03/2012     --- 2011-2012
    13     ---     01/04/2012 ---     30/04/2012     --- 2012-2013
    14     ---     01/05/2012 ---     31/05/2012     --- 2012-2013     
    My Requirement is get the Period_frm_dt,period_end_dt and yearcode based on period_code (which is input parameters from my procedure) by using Collections.
    I have to create one PLSQL table type which having the subscripts(Index) as period_code which is Varchar2 type;
    I have written follwing code ,but it's not giving the desired output:
    Declare
    iv_period Varchar2(10);
    Cursor cur_prd(cp_period Varchar2) is select * from Period_Master Where Period_code_c = cp_period;
    TYPE PRD_REC_TY IS TABLE OF cur_prd%ROWTYPE INDEX BY PLS_INTEGER;
    lv_prd_data prd_rec_ty;
    lv_prd PERIOD_MASTER.period_code_c%TYPE ;
    lv_frm_dt PERIOD_MASTER.Period_frm_dt%TYPE ;
    lv_to_dt PERIOD_MASTER.Period_to_dt%TYPE ;
    lv_yr_code PERIOD_MASTER.Year_code_c%TYPE ;
    Begin
    iv_period := :period;
    Open Cur_prd(iv_period);
    Loop
    Fetch cur_prd BULK COLLECT into lv_prd_data;
    EXIT WHEN cur_prd%NOTFOUND;
    End Loop;
    Close Cur_Prd;
    If lv_prd_data.COUNT > 0 THEN
    For i IN lv_prd_data.FIRST .. lv_prd_data.LAST
    LOOP
    lv_prd := lv_prd_data(i).pERIOD_cODE_C;
    lv_frm_dt := lv_prd_data(i).Period_frm_dt;
    lv_to_dt := lv_prd_data(i).Period_to_dt;
    lv_yr_code := lv_prd_data(i).Year_Code_c;
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Year code is : '||lv_yr_code);
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Period_from_dt is : '||lv_frm_dt);
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Period_to_dt is : '||lv_to_dt);
    END LOOP;
    End if;
    Exception
    When Others Then
    Dbms_output.Put_line('Here Error Found: '||SQLERRM);
    End;
    But My requirement is to get the FRM_DT,TO_DT and YEAR CODE as per the following:
    For Period Code :*11* -- the YearCode is --- *2011-2012*
    For Period Code :*11* -- the From Dt is --- *01/02/2012*
    For Period Code :*11* -- the To Dt is --- *29/02/2012*
    for Period Code : *14* -- the Yearcode is --- *2012-2013*
    For Period Code : *14* -- the From Dt is --- *01/05/2012*
    For Period Code : *14* -- the To Dt is --- *31/05/2012*
    So on...
    Like:
    lv_yr_code := lv_period_data(iv_period).Year_code_c;
    lv_frm_dt := lv_period_data(iv_period).Period_frm_dt;
    lv_to_dt := lv_period_data(iv_period).Period_to_dt;
    Dbms_output.Put_line('For Period code : '||iv_period||' the Year code is : '||lv_yr_code);
    Dbms_output.Put_line('For Period code : '||iv_period||' the Period_from_dt is : '||lv_frm_dt);
    Dbms_output.Put_line('For Period code : '||iv_period||' the Period_to_dt is : '||lv_to_dt);
    How do i resolve the above scenario.Please help me to resove the above scenario.
    Regards,
    Prasanta

    Hi, Pransanta,
    Prasanta wrote:
    ... My Requirement is get the Period_frm_dt,period_end_dt and yearcode based on period_code (which is input parameters from my procedure) by using Collections.Sorry, I don't understand.
    What is the porocedure you mentioned? Do you mean the anonymous block that you posted? If not, post the procedure. How is it related to the anonymous block? E.g., does the anonymous block need to call the procedure?
    I have to create one PLSQL table type which having the subscripts(Index) as period_code which is Varchar2 type;
    I have written follwing code ,but it's not giving the desired output:
    Declare
    iv_period Varchar2(10);Please format your code, and use \ tags to keep the formatting when you post it on this site.
    See the forum FAQ {message:id=9360002}
    Cursor cur_prd(cp_period Varchar2) is select * from Period_Master Where Period_code_c = cp_period;You're only looking for a single given period_code_c.  If you want to get all rows, lose the WHERE clause.  If you want to multiple rows, but not all rows, then use an appropriate WHERE clause.
    TYPE PRD_REC_TY IS TABLE OF cur_prd%ROWTYPE INDEX BY PLS_INTEGER;
    lv_prd_data prd_rec_ty;
    lv_prd PERIOD_MASTER.period_code_c%TYPE ;
    lv_frm_dt PERIOD_MASTER.Period_frm_dt%TYPE ;
    lv_to_dt PERIOD_MASTER.Period_to_dt%TYPE ;
    lv_yr_code PERIOD_MASTER.Year_code_c%TYPE ;
    Begin
    iv_period := :period;Post the code that declares and sets :period.
    Open Cur_prd(iv_period);
    Loop
    Fetch cur_prd BULK COLLECT into lv_prd_data;
    EXIT WHEN cur_prd%NOTFOUND;
    End Loop;
    Close Cur_Prd;
    If lv_prd_data.COUNT > 0 THEN
    For i IN lv_prd_data.FIRST .. lv_prd_data.LAST
    LOOP
    lv_prd := lv_prd_data(i).pERIOD_cODE_C;
    lv_frm_dt := lv_prd_data(i).Period_frm_dt;
    lv_to_dt := lv_prd_data(i).Period_to_dt;
    lv_yr_code := lv_prd_data(i).Year_Code_c;If the block is just supposed to do what it's doing now; then you don't need all these local variables.  It's simpler just to teference lv_prd_data.
    If you're planning to add some other code to the block later, then the local variables could be useful.
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Year code is : '||lv_yr_code);
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Period_from_dt is : '||lv_frm_dt);
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Period_to_dt is : '||lv_to_dt);
    END LOOP;
    End if;
    Exception
    When Others Then
    Dbms_output.Put_line('Here Error Found: '||SQLERRM);Only use an EXCEPTION section when you need to.  The EXCEPTION section above is only hiding some information about the error.
    End;
    But My requirement is to get the FRM_DT,TO_DT and YEAR CODE as per the following:
    For Period Code :*11* -- the YearCode is --- *2011-2012*
    For Period Code :*11* -- the From Dt is --- *01/02/2012*
    For Period Code :*11* -- the To Dt is --- *29/02/2012*
    for Period Code : *14* -- the Yearcode is --- *2012-2013*
    For Period Code : *14* -- the From Dt is --- *01/05/2012*
    For Period Code : *14* -- the To Dt is --- *31/05/2012*
    So on...
    Like:
    lv_yr_code := lv_period_data(iv_period).Year_code_c;
    lv_frm_dt := lv_period_data(iv_period).Period_frm_dt;
    lv_to_dt := lv_period_data(iv_period).Period_to_dt;
    Dbms_output.Put_line('For Period code : '||iv_period||' the Year code is : '||lv_yr_code);
    Dbms_output.Put_line('For Period code : '||iv_period||' the Period_from_dt is : '||lv_frm_dt);
    Dbms_output.Put_line('For Period code : '||iv_period||' the Period_to_dt is : '||lv_to_dt);
    How do i resolve the above scenario.Please help me to resove the above scenario.
    Regards,
    PrasantaIf the problem is that you need to show all period_code_cs, not just one, then you can do this:DECLARE
    CURSOR cur_prd
    IS SELECT *
         FROM     period_master
         ORDER BY period_code_c;
    TYPE prd_rec_ty IS TABLE OF cur_prd%ROWTYPE INDEX BY PLS_INTEGER;
    lv_prd_data prd_rec_ty;
    BEGIN
    OPEN cur_prd;
    FETCH cur_prd BULK COLLECT into lv_prd_data;
    CLOSE cur_prd;
    IF lv_prd_data.COUNT > 0
    THEN
    FOR i IN lv_prd_data.FIRST .. lv_prd_data.LAST
         LOOP
         dbms_output.put_line ( 'For Period code : '
                        || lv_prd_data(i).period_code_c
                        || ' the Year code is : '
                        || lv_prd_data(i).year_code_c
         dbms_output.Put_line ( 'For Period code : '
                        || lv_prd_data(i).period_code_c
                        || ' the Period_from_dt is : '
                        || lv_prd_data(i).period_frm_dt
         dbms_output.put_line ( 'For Period code : '
                        || lv_prd_data(i).period_code_c
                        || ' the Period_to_dt is : '
                        || lv_prd_data(i).period_to_dt
         END LOOP;
    END IF;
    END;

  • Associative Array to Nested Table: Anything faster?

    (First Post! Some ASP.NET references, but I think this really is a PL/SQL question)
    I work on a team that runs an Oracle instance for data warehousing and reporting along with an ASP.NET based website for display.
    Sometimes, I may want to have many parameters come in and only show records that match those parameters. For example, I may want to show all employees who are Managers or Developers and not show employees who are Accountants or Scientists. Typically, I send a parameter into my PL/SQL stored procedures as an associative array (as declared in my package specification). Once in the procedure, I convert that associative array into another associative array (as a user created SQL type) and then I'm able to use it like a nested table to join on.
    My question is: in your experience, is there any way to get around this type conversion or another faster way?
    For example:
    -- Create the sql type
    CREATE OR REPLACE TYPE DIM.sql_string_table AS TABLE OF VARCHAR2(255);
    --pretend that this works and it's in a package body
    declare
    type string_table is table of varchar2(255) index by binary_integer;
    l_job_types string_table; -- Keep in mind I'd normally be sending this via ASP.NET
    l_job_types_nested sql_string_table := sql_string_table();
    begin
    -- Add some data
    l_job_types(0) := 'Manager';
    l_job_types(1) := 'Developer';
    -- Do the conversion
    for i in l_job_types.first .. l_job_types.last
    loop
    l_job_types_nested.extend;
    l_job_types_nested(l_job_types_nested.count) := l_job_types(i);
    end loop;
    -- get some data out (we're pretending)
    open fake_ref_cursor for
    Select e.*
    from employees e,
    the(select cast(l_job_types_nested as sql_string_table) from dual) jobs_types_wanted
    where e.type = value(jobs_types_wanted);
    end;
    The result would be all employees whose have a type that was input into the l_job_types associatve array.
    See: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:110612348061
    for additional reference

    > I convert that associative array into another associative array (as a user created SQL type)
    Just so we're clear, Oracle use the term 'associative array' to refer to the exclusively PL/SQL sparse collection type ("table of x index by pls_integer" etc) as distinct from the common nested table collection type.
    Also I could be wrong but I think
    SELECT ..
    FROM   the(select cast(l_job_types_nested as sql_string_table) from dual) jobs_types_wantedis generally the same as
    SELECT ..
    FROM   TABLE(l_job_types_nested) jobs_types_wantedthough "SELECT *" and implicitly collection casting don't always mix. The "THE()" syntax is deprecated.

  • Associative Array, Drp-DwnList and Accesing "SubArray" Values ?

    Based on the users selection on a drop-down box, I need to be able to access different elements associated with that selection (elements of a subArray, so to speak)
    I am not certain how to go about creating arrays in LiveCycle. I've tried a number of things including:
    putting the array name in the "variables tab" of the Form Properties, with a value of [] -- that doesn't seen to be the way to go, so I removed it
    using rounded brackets ( instead of square [
    declaring the arrays differently using var codeDetail = new Array(array,Values,Here);
    putting the code in a fragment--not sure how to reference the values,
    I have the following code residing in the "Exit" event for the drop-down box:
    var codeDetail = [];   //an associative array
    codeDetail["99999"] = ["None",null,null,null,null,null,null,null];
    codeDetail["78400"] = ["Trampoline",40,45,50,60,10,20,40];
    codeDetail["78020"] = ["Horse(s)",10,12,15,20,5,10, 20];
    codeDetail["78401"] = ["Horse Boarding (each)",19,23,28,39,17,24,48];
    codeDetail["78010"] = ["Watercraft - Outboard over 50 HP (each)",13,18,20,24,17,24,48];
    codeDetail["78011"] = ["Watercraft - Inboard or I/O over 50 HP (each)",30,35,40,50,17,24,48];
    codeDetail["78050"] = ["Recreational Vehicle: ATV (each)",40,51,61,84,9,11,22];
    codeDetail["78053"] = ["Recreational Vehicle: Snowmobiles (each)",36,46,55,76,9,11,22];
    codeDetail["78052"] = ["Recreational Vehicle: Golf Carts (each)",29,37,44,61,9,11,22];
    codeDetail["73000"] = ["Personal Injury",14,19,22,31,null,null,null];
    codeDetail["78030"] = ["Office, School or Studio",10,11,13,19,9,17,34];
    codeDetail["78060"] = ["Retail Sales",36,46,56,77,3,4,8];
    codeDetail["78061"] = ["Incidental Business Pursuits",36,46,56,77,3,4,8];
    codeDetail["78070"] = ["Additional Insured: Premises Only",8,10,12,17,null,null,null];
    codeDetail["78090"] = ["Additional Insured - Personal Libility",31,40,50,69,9,17,34];
    codeDetail["78040"] = ["Seasonal Residence Occupied by Insured",10,11,13,19,3,4,8];
    codeDetail["78041"] = ["Rented to Others: One Family",23,28,34,47,9,17,34];
    codeDetail["78042"] = ["Rented to Others: Two Family",29,35,43,61,11,23,45];
    codeDetail["78043"] = ["Rented to Others: Three Family",43,55,66,90,17,33,60];
    codeDetail["78044"] = ["Rented to Others: Four Family",67,83,100,139,24,50,80];
    codeDetail["76000"] = ["Waterbed Liability",10,12,13,19,null,null,null];
    codeDetail["78300"] = ["Non-Owned and Hired Auto Liability",56,69,80,92,17,24,48];
    itemChosen = [];  //a subArray
    var i = this.rawValue
    itemChosen = [codeDetail[i]];    //  values based on user's selection
    The goal is to now be able to use the itemChosen values and simply refer to them:
    this.rawValue = itemChosen[i]   or   this.rawValue = itemChosen[someField.rawValue]
    So if this drop-down box has a rawValue = "78400" then itemChosen[2] would have a value of 45 (see above).
    Am I anywhere close?
    Also, a couple of other questions:
    When using a variable.value or a field.rawValue as the index value for itemChosen[i]
    do you include "" or .value or .rawValue in the index brackets?
    Do you ever use .value when referencing an array as in: itemChosen[i].value
    How do I make sure arrays and variables created like this are global, or not? I tried with and without the "var" declaration
    Thanks much!
    Stephen

    I've just been playing with a similar thing.
    My code is based on a sample from WindJack Solutions, which is available here:
    http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle
    Check this thread for a good sample from Bruce, he took my code and jacked it up considerably.
    http://forums.adobe.com/message/2203834#2203834
    If you google "multi dimensional javascript arrays" you'll find quite a bit of info too.

Maybe you are looking for

  • Imovie won't open any projects after upgrading to yosemite

    Can anyone help? I upgraded to yosemite and imovie 10.0.6 and now imovie won't open. IPhoto and Garageband open just fine. After clicking Imovie, it appears in the menu bar but all options from the drop down menus are grayed out. I cannot open any pr

  • Horizontal Menu Bar works when index.html is appended to url, but not otherwise

    My spry horizontal menu bar works like I want when I put /index.html at the end of the url for my website, but when I just go to the website without typing that in the index page shows up fine, but some of the links in the menu don't work. How is tha

  • ORABPEL-09705

    Hi All, Using JDeveloper 11.1.1.5 , Oracle SOA Suite 11g BPEL A developer gave me a URL = http://AVEPOC04/AFDM/AFDMService.svc Steps I took: 1.Used IE to get the source data , that I used to create a WSDL file. 2.Created a Partner link in BPEL with t

  • Dynamic in SELECT statement

    Hi, I have a SELECT statement where I need the year to be dynamic. The user select a range of months where the script should execute and based on the input I would like to create a dynamic SELECT statement. My SELECT statement looks like: *SELECT(%TI

  • PC Suite wont backup !! 6680

    Have just upgraded my 6680 to the latest firmware. Using PC suite, no problems at all. However when I went to backup to restore my original settings it said that it had not completed and to do it again, now when I click the backup icon it ignores me