PLSQL COLLECTIONS(10g)

Hi People,
I have a clarification in plsql collections.it is defined that plsql collections are used to collect values of same data type.but in 10g document it is told that you can also use INDEX BY tables along with %ROWTYPE.how this is possible?.%ROWTYPE is used to draw different data types.how to use this along with INDEX BY tables. Pls help me with some sample codes.
with regards
vids

vidusnat wrote:
In the above example plsql table is used with %ROWTYPE It is not a PL/SQL "+table+". There is no such thing. No such concept. It is INCORRECT terminology used by many, including Oracle. (Oracle has however corrected this terminology in recent documentation).
That type defines an associative array.
which is used to collect values of different data types.Correct. The +%RowType+ clause saves us time and effort in redefining a PL/SQL record structure that duplicates the structure (SQL projection) of a table, view or cursor.
So in effect, instead of having to code this, we use +%RowType+ instead.
declare
  type TEmployeeRecord is record(
    emp_id number,
    surname varchar2(80),
   .. etc ..
  type EmpTabTyp is table of TEmployeeRecord
    index by pls_integer;To manually define a structure like this each time for a table/view/cursor is lots of coding. Easy to get wrong. And if the underlying SQL projection changes, then we need to manually update the structure.
So +%RowType+ saves us all the extra coding and maintenance of defining a PL/SQL struct that duplicates a SQL projection structure. If you know C/C++, think of it as a compiler macro that defines the relevant struct for you.
but plsql collections are defined to collect values of same data type.You have not define a collection. A collection is a different type of structure and has different features. You have defined an associative array.
using %ROWTYPE is contrary to plsql collection's definition.can anyone pls explain me how it is possible?There is no contradiction here. Just confusion it seems?
A collection is not an associative array. An associative array is not a collection. Both can be based on the same structure. Both can be used to received SQL cursor output. However, there are differences in features - especially how one addresses the contents. In essence, an associative array is addressed via name. Each cell in the array is named - or in the case of the name being a numeric, a number value. The 1st cell in the associative array can be named (or numbered in your case) using "100" - as you did in your sample code. So to address the contents of the 1st cell in that array, you need to reference it by index value 100. Not 1.
A collection is not addressed via a name of the cell. Instead, it is addressed by location/position of the cell. So the 1st cell will be addressed by 1, the 2nd cell by 2 and so on.

Similar Messages

  • How to fetch from cursor into plsql collection

    Dear Friends,
    I am trying to understand PLSQL collections. I am trying with the following example.
    CREATE OR REPLACE TYPE emp_obj AS OBJECT
    (     empname          VARCHAR2(100),     empjob          VARCHAR2(50),     empsal          NUMBER);
    CREATE OR REPLACE TYPE emp_tbl IS TABLE OF emp_obj;
    CREATE OR REPLACE PACKAGE eg_collection AS
    -- Delcare ref cursor
    TYPE rc IS REF CURSOR;
    -- Procedure
    PROCEDURE eg_collection_proc (out_result OUT rc);
    END;
    CREATE OR REPLACE PACKAGE BODY eg_collection AS
    PROCEDURE eg_collection_proc( out_result OUT rc) AS
    emp_tdt     emp_tbl := emp_tbl(emp_obj('oracle','DBA',100));
    CURSOR c2 IS SELECT ename,job,sal FROM emp WHERE sal > 2000;
    -- Declare a record type to hold the records from cursor and then pass to the collection
    emp_rec emp_obj;
    BEGIN
         OPEN c2;
         LOOP FETCH c1 INTO emp_rec;
              EXIT WHEN c1%NOTFOUND;
              emp_tdt.extend;
    emp_tdt(emp_tdt.count) := emp_rec;
         END LOOP;
         CLOSE c2;
    OPEN out_result FOR SELECT * FROM TABLE(CAST(emp_tdt AS emp_tbl));
    END eg_collection_proc;
    END eg_collection;
    Executing the proc
    variable r refcursor;
    exec eg_collection.eg_collection_proc(:r);
    print r;
    But I am getting compilation error type mismatch found at emp_rec between fetch cursor into variable

    I am trying to understand PLSQL collections. I dont why the code is not working
    SQL> CREATE OR REPLACE TYPE emp_obj AS OBJECT
    2 (
    3      empname          VARCHAR2(100),
    4      empjob          VARCHAR2(50),
    5      empsal          NUMBER
    6 )
    7 /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_tbl IS TABLE OF emp_obj
    2 /
    Type created.
    SQL> DECLARE
    2      emp_tdt emp_tbl := emp_tbl ();
    3 BEGIN
    4
    5      emp_tdt.extend;
    6      SELECT emp_obj(ename, job, sal) BULK COLLECT INTO emp_tdt
    7      FROM emp WHERE sal < 4000;
    8
    9      DBMS_OUTPUT.PUT_LINE ('The total count is ' || emp_tdt.count);
    10
    11      emp_tdt.extend;
    12      SELECT ename, job, sal INTO emp_tdt(1).empname, emp_tdt(1).empjob, emp_tdt(1).empsal
    13      FROM emp WHERE empno = 7900;
    14
    15      DBMS_OUTPUT.PUT_LINE ('The total count is ' || emp_tdt.count);
    16
    17 END;
    18 /
    The total count is 13
    The total count is 14
    PL/SQL procedure successfully completed.
    SQL> DECLARE
    2      emp_tdt emp_tbl := emp_tbl ();
    3 BEGIN
    4
    5      emp_tdt.extend;
    6      SELECT ename, job, sal INTO emp_tdt(1).empname, emp_tdt(1).empjob, emp_tdt(1).empsal
    7      FROM emp WHERE empno = 7900;
    8
    9      DBMS_OUTPUT.PUT_LINE ('The total count is ' || emp_tdt.count);
    10
    11      emp_tdt.extend;
    12      SELECT emp_obj(ename, job, sal) BULK COLLECT INTO emp_tdt
    13      FROM emp WHERE sal < 4000;
    14
    15      DBMS_OUTPUT.PUT_LINE ('The total count is ' || emp_tdt.count);
    16 END;
    17 /
    DECLARE
    ERROR at line 1:
    ORA-06530: Reference to uninitialized composite
    ORA-06512: at line 6

  • Wat's Plsql collections?

    Can anyone help me about Plsql collections and why we need this?

    Welcome to the forum.
    Your question is quite broad.
    A quick search through the Oracle docs will give you explanations and examples
    http://www.oracle.com/pls/db112/search?remark=quick_search&word=collections
    http://www.oracle.com/pls/db112/homepage
    As well as a search on AskTom, for example:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3170352229012
    As well as a search on this forum.
    why we need this?It depends. Perhaps you don't need them, perhaps you do.
    Amongst others on your specific requirement and your datamodel.

  • Plsql Collections help

    Database table has two columns category and products.
    Table: catalog
    category products
    fruit apple
    vegetable carrot
    soda pepsi
    vegetable potato
    fruit grapes
    fruit orange
    vegetable cabbage
    soda coke
    i need to read the records from table catalog and store them in some sort of plsql collection. I then have to read from that collection and write output as follows:
    Note: the categories and products should be sorted alphabetically in output.
    OUTPUT
    fruit apple, grapes, orange
    soda coke, pepsi
    vegetable cabbage, carrot, potato
    please help me as how this can be done?
    Thanks
    G

    Without collections:
    SQL> DECLARE
      2      CURSOR c
      3        IS
      4          WITH t AS (
      5                     SELECT 'fruit' category,'apple' product FROM dual UNION ALL
      6                     SELECT 'vegetable','carrot' FROM dual UNION ALL
      7                     SELECT 'soda','pepsi' FROM dual UNION ALL
      8                     SELECT 'vegetable','potato' FROM dual UNION ALL
      9                     SELECT 'fruit','grapes' FROM dual UNION ALL
    10                     SELECT 'fruit','orange' FROM dual UNION ALL
    11                     SELECT 'vegetable','cabbage' FROM dual UNION ALL
    12                     SELECT 'soda','coke' FROM dual
    13                    )
    14          SELECT  category,
    15                  ltrim(sys_connect_by_path(product,', '),', ') product_list
    16            FROM  (
    17                   SELECT  category,
    18                           product,
    19                           row_number() over(partition by category order by product) rn
    20                     FROM  t
    21                  )
    22            WHERE connect_by_isleaf = 1
    23            START WITH rn = 1
    24            CONNECT BY category = PRIOR category
    25                   AND rn = PRIOR rn + 1
    26            ORDER BY category;
    27  BEGIN
    28      FOR v_rec IN c LOOP
    29        DBMS_OUTPUT.PUT_LINE(rpad(v_rec.category,10) || v_rec.product_list);
    30      END LOOP;
    31  END;
    32  /
    fruit     apple, grapes, orange
    soda      coke, pepsi
    vegetable cabbage, carrot, potato
    PL/SQL procedure successfully completed.
    SQL> And in plain SQL:
    SQL> COLUMN PRODUCT_LIST FORMAT A50
    SQL> WITH t AS (
      2             SELECT 'fruit' category,'apple' product FROM dual UNION ALL
      3             SELECT 'vegetable','carrot' FROM dual UNION ALL
      4             SELECT 'soda','pepsi' FROM dual UNION ALL
      5             SELECT 'vegetable','potato' FROM dual UNION ALL
      6             SELECT 'fruit','grapes' FROM dual UNION ALL
      7             SELECT 'fruit','orange' FROM dual UNION ALL
      8             SELECT 'vegetable','cabbage' FROM dual UNION ALL
      9             SELECT 'soda','coke' FROM dual
    10            )
    11  SELECT  category,
    12          ltrim(sys_connect_by_path(product,', '),', ') product_list
    13    FROM  (
    14           SELECT  category,
    15                   product,
    16                   row_number() over(partition by category order by product) rn
    17             FROM  t
    18          )
    19    WHERE connect_by_isleaf = 1
    20    START WITH rn = 1
    21    CONNECT BY category = PRIOR category
    22           AND rn = PRIOR rn + 1
    23    ORDER BY category
    24  /
    CATEGORY  PRODUCT_LIST
    fruit     apple, grapes, orange
    soda      coke, pepsi
    vegetable cabbage, carrot, potato
    SQL> SY.

  • Plsql collections

    Hi,
    I am working with oracle 10g.
    Still i was not familiar with PLSQL Tables or collections.
    Please send me the link or any notes regarding PLSQL Tables.
    Thanks and Regards,
    Ansaf.

    Ansaf wrote:
    Hi,
    I am working with oracle 10g.
    Still i was not familiar with PLSQL Tables or collections.
    Please send me the link or any notes regarding PLSQL Tables.
    Thanks and Regards,
    Ansaf.when all else fail Read The Fine Manual
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#sthref1031

  • Select data from plsql collections

    Hi All,
    I am not a developer but working as a DBA, so not very much familiar with pl/sql, still gone through with documentation and could come up with some solution of my problem. I need some expert advice here.
    Problem : I am writing down some kind of plsql program for monitoring of some special batch job, I know we have lot of other option to do the same including db/grid control ..etc but for some
    reason i have to do this using plsql only.
    Requirement : my requirement is to select data from table in plsql and then should have ability to query it again and again. I would not prefer to go to table rather than directly from plsql..
    I wrote down below code for sample, bulk collect data into collection type and can print using for loop.
    Declare
    type ts is table of v$session%rowtype index by pls_integer;
    tsess ts;
    begin
    select * bulk collect into tsess from v$session ;
    for i in 1..tsess.count loop
    dbms_output.put_line(tsess(i).terminal);
    end loop;
    end;
    But, is there any way same collection ( tsess in above example ) can be queried using select statement like 'select * from table ( Tsess ) ' I have searched on net and found this can be done using creating type at database level. But my problem is I can not create any object in database as being it is a production one.
    I was looking for if is there any way same can be accomplished ... like cast / multiset .. however, I could not get it through.
    your help would be appreciated !!
    Regards,

    I don't think you need to use arrays here, only SQL, have a look at subquery factors and report back if that is insufficient...
    Edited by: BrendanP on 12-Feb-2012 03:07 to add an example:
    I gather that you want to 'requery' data that you have already got from the database purely to be able to use SQL functionality such as ORDER BY in multiple ways. Here is how you can do this in the original SQL for one particular example, where you want to query v$sql ordering by CPU time and by disk reads separately (I tested this but the output won't look good here, so omitting it):
    WITH v AS (
    SELECT
        Substr (sql_text,1,500)             sql_text,
        cpu_time/1000000                    cpu_seconds,
        disk_reads,
        buffer_gets,
        executions,
        CASE WHEN rows_processed != 0 THEN Round( buffer_gets / Nvl (Replace (rows_processed, 0, 1) ,1)) END Buffer_gets_rows_proc,
        Round (buffer_gets / Nvl (Replace (executions, 0, 1), 1)) Buffer_gets_executions,
        elapsed_time / 1000000              elapsed_second,
        module
    FROM v$sql s)
    SELECT
        'CPU'                order_by,
        cpu_seconds          order_val,
        sql_text,
        cpu_seconds,
        disk_reads,
        buffer_gets,
        executions,
        buffer_gets_rows_proc,
        buffer_gets_executions,
        elapsed_second,
        module
    FROM v
    UNION
    SELECT
        'Disk reads',
        disk_reads,
        sql_text,
        cpu_seconds,
        disk_reads,
        buffer_gets,
        executions,
        buffer_gets_rows_proc,
        buffer_gets_executions,
        elapsed_second,
        module
    FROM v
    ORDER BY order_by, order_val DESC

  • PLSQL Collections and record types

    Hi,
    I'm trying to use collection in my code in 10g database
    declare
    cursor c_cur
    is
    select  * from table;
    TYPE tbl_cur_lines IS TABLE OF c_cur%ROWTYPE
          INDEX BY BINARY_INTEGER;
          l_cur_rec    tbl_cur_lines;
    begin
    OPEN c_cur;
    FETCH c_cur BULK COLLECT INTO l_cur_rec;
    CLOSE c_open_trx;                       
    FOR i IN 0..l_cur_rec.COUNT-1
    LOOP
              --  do something
    END LOOP;
    end;if i use count for number of records its working
    declare
    cursor c_cur
    is
    select  * from table;
    TYPE tbl_cur_lines IS TABLE OF c_cur%ROWTYPE
          INDEX BY BINARY_INTEGER;
          l_cur_rec    tbl_cur_lines;
    begin
    OPEN c_cur;
    FETCH c_cur BULK COLLECT INTO l_cur_rec;
    CLOSE c_open_trx;                       
    FOR i IN l_cur_rec.FIRST..l_cur_rec.LAST
    LOOP
              --  do something
    END LOOP;
    end;If i use above code i'm getting following error
    ORA-06502: PL/SQL: numeric or value error
    Can some explain difference...
    Thanks in advance!
    Edited by: user641008 on Jun 3, 2011 2:31 PM

    FOR i IN 0..l_cur_rec.COUNT-1
    here, index "i" expect an integer value and it is getting and integer, hence not
    giving an error, though your cursor did not fetch any row.
    in the next case,
    FOR i IN l_cur_rec.FIRST..l_cur_rec.LAST
    your cursor did not fetch any row and hence
    first element in your collection is NULL( in other words, there is no index value in collection) while "i" is expecting an integer,
    thats why you are getting error "ORA-06502: PL/SQL: numeric or value error"
    It is always good practice, check collection count before actually processing by loop.
    Change as follows
    declare
    cursor c_cur
    is
    select  * from table;
    TYPE tbl_cur_lines IS TABLE OF c_cur%ROWTYPE
          INDEX BY BINARY_INTEGER;
          l_cur_rec    tbl_cur_lines;
    begin
    OPEN c_cur;
    FETCH c_cur BULK COLLECT INTO l_cur_rec;
    CLOSE c_cur;                       
    if  l_cur_rec.count>0 then      -- Add condition here
    FOR i IN l_cur_rec.FIRST..l_cur_rec.LAST
    LOOP
              --  do something
    END LOOP;
    end if;
    end;

  • How Track&monitor the history of executed sql /plsql on 10g database server

    I want to keep and track the history of all sql/plsql that is being execute on database server. how it is to be done.
    pls help
    prabhaker

    To keep track of executed SQL statements, you can use database auditing : see http://oraclelon1.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4007.htm#i2059073
    I am not sure that PL/SQL execution can be traced using database auditing.

  • How to declare and use multi dimensional VARRAYs in PLSQL

    Hi All,
    I am trying to create and use multidimensional varray in plsql code...
    can anyone let me know, how can I do this...
    Thanks
    Krishna

    Please do not confuse plsql collections with type objects.Well it's possible with persistent types but nested tables and varrays typically need to be explicitly initialized and extended.
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> CREATE OR REPLACE TYPE name_type_size IS VARRAY (3) OF VARCHAR2 (50);
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE name_type_size_array IS VARRAY (200) OF name_type_size;
      2  /
    Type created.
    SQL> DECLARE
      2     i_name_type_size_array name_type_size_array :=  name_type_size_array ();
      3  BEGIN
      4     FOR count1 IN 1 .. 200 LOOP
      5
      6        i_name_type_size_array.EXTEND;
      7        i_name_type_size_array (count1) := name_type_size ();
      8
      9        FOR count2 IN 1 .. 3 LOOP
    10
    11           i_name_type_size_array (count1).EXTEND;
    12           i_name_type_size_array (count1) (count2) := count2;
    13
    14        END LOOP;
    15
    16     END LOOP;
    17  END;
    18  /
    PL/SQL procedure successfully completed.
    SQL>

  • Need Advise and Suggestions-Oracle 10g

    Hi,
    I have been working on databases as DB developer(mainly PLsql)--Oracle 10g
    Recently,i have joined in a particular position where I have been asked to find out areas where
    improvement is necessary / or areas where improvement or changes would help very much and also gradually implement all best practises avaialable.
    So,could you please help me with these queries
    (1)What are the most important areas that i can start with the database which would impact largely the entire database.How can i start with it? any steps or process
    (2)I had once taken a report out for the expensive SQLs running.But that dint help much...because those SQLs were used temporarily on and off.
    Similarly,what are the other points to be looked on.
    (3)Things which can be replaced with the industry standarad better ones fully.
    an example would be...like.."following a particular naming format,or coding style,etc
    Thanks
    Rohit

    Hi Rohit,
    This is a pretty huge subject. To start, I'd say you need to talk to the business. Talk to the users of the database, cause they are your customers. Get a clear understanding of the most critical business processes. Start with the most critical ones, and get performance profiles. How long do they take to run? What's the customer's perception of the process performance? If it's acceptable, move on to the next one. If it's not acceptable, you'll need to dig deeper. Look at each piece of the process. Where is the most time being spent? Can it be improved? This step will be a combination of process improvement and setting the correct expectation. Often, the user doesn't really know what is realistic in terms of performance. If you have a 2 billion row table that needs to get full table scanned, expecting a response time of a few seconds just simply isn't going to happen. You need to clearly convey that to the customer. On the other hand, at the same time, you should be on the lookout for real improvements. If you can re-write the SQL or add an index, and eliminate the FTS on that 2 billion row table, maybe a response time of a few seconds is actually realistic.
    It's all about understanding the system, and understanding the customer's needs, and how they intersect. It will be an iterative process, and will take some time.
    As to "best practices", I'm not a fan of them. Understand your system, understand your customer's needs, and understand how Oracle actually works. If you can master that, you'll be unstoppable. Note that many, many people, much smarter people than me, have spent a lifetime trying to master those three points... :-)
    Good luck with your new job!
    -Mark

  • BULK COLLECT in select query inside a function

    Hi All,
    My query is :
    SELECT col1,col2,col3 FROM table_a; --( consider this is a long running query with lot of joins)
    Need to know how can i get the output of the above query from a function using BULK COLLECT.
    and i tried this:
    CREATE OR REPLACE TYPE tab_a_row
    AS OBJECT (
    col1 number(20),
    col2 number(20),
    col2 number(20)) ;
    create or replace type tab_a_nt as table of tab_a_row;
    create or replace function get_table_a
    return sys_refcursor
    is
    tab_a_recs tab_a_nt;
    rv sys_refcursor;
    begin
    SELECT tab_a_row(col1,col2,col3) BULK COLLECT INTO tab_a_recs FROM table_a;
    open rv for select * from table(tab_a_recs);
    return rv;
    end;
    Function created successfully. and i exec this from sql plus using
    SQL> var rc refcursor;
    SQL> exec :rc := get_table_a;
    BEGIN :rc := get_table_a; END;
    ERROR at line 1:
    ORA-22905: cannot access rows from a non-nested table item
    ORA-06512: at "GET_TABLE_A", line 12
    ORA-06512: at line 1
    Kindly share your ideas on how to use bulk collect and get set of outputs from a function.
    Edited by: 887268 on Apr 18, 2013 3:10 AM

    >
    If i use refcursor , then the JAVA code needs to be changed accordinglyto get the refcursor output.
    >
    Well, of course. Java has to know what the sql projection is. How else will it know how many columns there are and their datatypes.
    But that is true no matter what method you use.
    >
    But if i use a PLSQL COLLECTION TYPE (nested tables ) , then i can get output as ,
    select * from table(function_name(input1,input2));
    >
    No - using the 'table' function mean you are calling a PIPELINED function.
    This is a sample of a PIPELINED procedure.
    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
    -- pipelined function
    create or replace function get_emp( p_deptno in number )
      return emp_table_type
      PIPELINED
      as
       TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
        emp_cv EmpCurTyp;
        l_rec  emp%rowtype;
      begin
        open emp_cv for select * from emp where deptno = p_deptno;
        loop
          fetch emp_cv into l_rec;
          exit when (emp_cv%notfound);
          pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
              l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
        end loop;
        return;
      end;
    select * from table(get_emp(20))Or your function could return a collection like the example from this thread this morning.
    Example of Collection as datatype of a function’s return value
    CREATE OR REPLACE TYPE enamelist as VARRAY(20) of VARCHAR2(20)
    /* Formatted on 4/18/2013 4:06:47 PM (QP5 v5.126.903.23003) */
    CREATE OR REPLACE FUNCTION ename_fn
    RETURN enamelist
    AS
    v_cursor_main enamelist := enamelist ();
    BEGIN
    SELECT ename
    BULK COLLECT
    INTO v_cursor_main
    FROM emp;
    RETURN v_cursor_main;
    EXCEPTION
    WHEN OTHERS
    THEN
    RETURN v_cursor_main;
    END;
    select * from table(ename_fn()) from dual;
    COLUMN_VALUE
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER

  • Problem with BULK COLLECT with million rows - Oracle 9.0.1.4

    We have a requirement where are supposed to load 58 millions of rows into a FACT Table in our DATA WAREHOUSE. We initially planned to use Oracle Warehouse Builder but due to performance reasons, decided to write custom code. We wrote a custome procedure which opens a simple cursor and reads all the 58 million rows from the SOURCE Table and in a loop processes the rows and inserts the records into a TARGET Table. The logic works fine but it took 20hrs to complete the load.
    We then tried to leverage the BULK COLLECT and FORALL and PARALLEL options and modified our PL/SQL code completely to reflect these. Our code looks very simple.
    1. We declared PL/SQL BINARY_INDEXed Tables to store the data in memory.
    2. We used BULK COLLECT into FETCH the data.
    3. We used FORALL statement while inserting the data.
    We did not introduce any of our transformation logic yet.
    We tried with the 600,000 records first and it completed in 1 min and 29 sec with no problems. We then doubled the no. of rows to 1.2 million and the program crashed with the following error:
    ERROR at line 1:
    ORA-04030: out of process memory when trying to allocate 16408 bytes (koh-kghu
    call ,pmucalm coll)
    ORA-06512: at "VVA.BULKLOAD", line 66
    ORA-06512: at line 1
    We got the same error even with 1 million rows.
    We do have the following configuration:
    SGA - 8.2 GB
    PGA
    - Aggregate Target - 3GB
    - Current Allocated - 439444KB (439 MB)
    - Maximum allocated - 2695753 KB (2.6 GB)
    Temp Table Space - 60.9 GB (Total)
    - 20 GB (Available approximately)
    I think we do have more than enough memory to process the 1 million rows!!
    Also, some times the same program results in the following error:
    SQL> exec bulkload
    BEGIN bulkload; END;
    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    We did not even attempt the full load. Also, we are not using the PARALLEL option yet.
    Are we hitting any bug here? Or PL/SQL is not capable of mass loads? I would appreciate any thoughts on this?
    Thanks,
    Haranadh
    Following is the code:
    set echo off
    set timing on
    create or replace procedure bulkload as
    -- SOURCE --
    TYPE src_cpd_dt IS TABLE OF ima_ama_acct.cpd_dt%TYPE;
    TYPE src_acqr_ctry_cd IS TABLE OF ima_ama_acct.acqr_ctry_cd%TYPE;
    TYPE src_acqr_pcr_ctry_cd IS TABLE OF ima_ama_acct.acqr_pcr_ctry_cd%TYPE;
    TYPE src_issr_bin IS TABLE OF ima_ama_acct.issr_bin%TYPE;
    TYPE src_mrch_locn_ref_id IS TABLE OF ima_ama_acct.mrch_locn_ref_id%TYPE;
    TYPE src_ntwrk_id IS TABLE OF ima_ama_acct.ntwrk_id%TYPE;
    TYPE src_stip_advc_cd IS TABLE OF ima_ama_acct.stip_advc_cd%TYPE;
    TYPE src_authn_resp_cd IS TABLE OF ima_ama_acct.authn_resp_cd%TYPE;
    TYPE src_authn_actvy_cd IS TABLE OF ima_ama_acct.authn_actvy_cd%TYPE;
    TYPE src_resp_tm_id IS TABLE OF ima_ama_acct.resp_tm_id%TYPE;
    TYPE src_mrch_ref_id IS TABLE OF ima_ama_acct.mrch_ref_id%TYPE;
    TYPE src_issr_pcr IS TABLE OF ima_ama_acct.issr_pcr%TYPE;
    TYPE src_issr_ctry_cd IS TABLE OF ima_ama_acct.issr_ctry_cd%TYPE;
    TYPE src_acct_num IS TABLE OF ima_ama_acct.acct_num%TYPE;
    TYPE src_tran_cnt IS TABLE OF ima_ama_acct.tran_cnt%TYPE;
    TYPE src_usd_tran_amt IS TABLE OF ima_ama_acct.usd_tran_amt%TYPE;
    src_cpd_dt_array src_cpd_dt;
    src_acqr_ctry_cd_array      src_acqr_ctry_cd;
    src_acqr_pcr_ctry_cd_array     src_acqr_pcr_ctry_cd;
    src_issr_bin_array      src_issr_bin;
    src_mrch_locn_ref_id_array     src_mrch_locn_ref_id;
    src_ntwrk_id_array      src_ntwrk_id;
    src_stip_advc_cd_array      src_stip_advc_cd;
    src_authn_resp_cd_array      src_authn_resp_cd;
    src_authn_actvy_cd_array      src_authn_actvy_cd;
    src_resp_tm_id_array      src_resp_tm_id;
    src_mrch_ref_id_array      src_mrch_ref_id;
    src_issr_pcr_array      src_issr_pcr;
    src_issr_ctry_cd_array      src_issr_ctry_cd;
    src_acct_num_array      src_acct_num;
    src_tran_cnt_array      src_tran_cnt;
    src_usd_tran_amt_array      src_usd_tran_amt;
    j number := 1;
    CURSOR c1 IS
    SELECT
    cpd_dt,
    acqr_ctry_cd ,
    acqr_pcr_ctry_cd,
    issr_bin,
    mrch_locn_ref_id,
    ntwrk_id,
    stip_advc_cd,
    authn_resp_cd,
    authn_actvy_cd,
    resp_tm_id,
    mrch_ref_id,
    issr_pcr,
    issr_ctry_cd,
    acct_num,
    tran_cnt,
    usd_tran_amt
    FROM ima_ama_acct ima_ama_acct
    ORDER BY issr_bin;
    BEGIN
    OPEN c1;
    FETCH c1 bulk collect into
    src_cpd_dt_array ,
    src_acqr_ctry_cd_array ,
    src_acqr_pcr_ctry_cd_array,
    src_issr_bin_array ,
    src_mrch_locn_ref_id_array,
    src_ntwrk_id_array ,
    src_stip_advc_cd_array ,
    src_authn_resp_cd_array ,
    src_authn_actvy_cd_array ,
    src_resp_tm_id_array ,
    src_mrch_ref_id_array ,
    src_issr_pcr_array ,
    src_issr_ctry_cd_array ,
    src_acct_num_array ,
    src_tran_cnt_array ,
    src_usd_tran_amt_array ;
    CLOSE C1;
    FORALL j in 1 .. src_cpd_dt_array.count
    INSERT INTO ima_dly_acct (
         CPD_DT,
         ACQR_CTRY_CD,
         ACQR_TIER_CD,
         ACQR_PCR_CTRY_CD,
         ACQR_PCR_TIER_CD,
         ISSR_BIN,
         OWNR_BUS_ID,
         USER_BUS_ID,
         MRCH_LOCN_REF_ID,
         NTWRK_ID,
         STIP_ADVC_CD,
         AUTHN_RESP_CD,
         AUTHN_ACTVY_CD,
         RESP_TM_ID,
         PROD_REF_ID,
         MRCH_REF_ID,
         ISSR_PCR,
         ISSR_CTRY_CD,
         ACCT_NUM,
         TRAN_CNT,
         USD_TRAN_AMT)
         VALUES (
         src_cpd_dt_array(j),
         src_acqr_ctry_cd_array(j),
         null,
         src_acqr_pcr_ctry_cd_array(j),
              null,
              src_issr_bin_array(j),
              null,
              null,
              src_mrch_locn_ref_id_array(j),
              src_ntwrk_id_array(j),
              src_stip_advc_cd_array(j),
              src_authn_resp_cd_array(j),
              src_authn_actvy_cd_array(j),
              src_resp_tm_id_array(j),
              null,
              src_mrch_ref_id_array(j),
              src_issr_pcr_array(j),
              src_issr_ctry_cd_array(j),
              src_acct_num_array(j),
              src_tran_cnt_array(j),
              src_usd_tran_amt_array(j));
    COMMIT;
    END bulkload;
    SHOW ERRORS
    -----------------------------------------------------------------------------

    do you have a unique key available in the rows you are fetching?
    It seems a cursor with 20 million rows that is as wide as all the columnsyou want to work with is a lot of memory for the server to use at once. You may be able to do this with parallel processing (dop over 8) and a lot of memory for the warehouse box (and the box you are extracting data from)...but is this the most efficient (and thereby fastest) way to do it?
    What if you used a cursor to select a unique key only, and then during the cursor loop fetch each record, transform it, and insert it into the target?
    Its a different way to do a lot at once, but it cuts down on the overall memory overhead for the process.
    I know this isnt as elegant as a single insert to do it all at once, but sometimes trimming a process down so it takes less resources at any given moment is much faster than trying to do the whole thing at once.
    My solution is probably biased by transaction systems, so I would be interested in what the data warehouse community thinks of this.
    For example:
    source table my_transactions (tx_seq_id number, tx_fact1 varchar2(10), tx_fact2 varchar2(20), tx_fact3 number, ...)
    select a cursor of tx_seq_id only (even at 20 million rows this is not much)
    you could then either use a for loop or even bulk collect into a plsql collection or table
    then process individually like this:
    procedure process_a_tx(p_tx_seq_id in number)
    is
    rTX my_transactions%rowtype;
    begin
    select * into rTX from my_transactions where tx_seq_id = p_tx_seq_id;
    --modify values as needed
    insert into my_target(a, b, c) values (rtx.fact_1, rtx.fact2, rtx.fact3);
    commit;
    exception
    when others
    rollback;
    --write to a log or raise and exception
    end process_a_tx;
    procedure collect_tx
    is
    cursor tx is
    select tx_seq_id from my_transactions;
    begin
    for rTx in cTx loop
    process_a_tx(rtx.tx_seq_id);
    end loop;
    end collect_tx;

  • Converting from JAVA HASHMAP to PLSQL object or CLOB

    Hello All,
    My oracle version in 10.2.0.4 on a solaris V880 machine.
    Our Application Java SDK is 1.4.
    I am trying to pass in a series of XML (considerably huge for XML type column) from java application plsql which stores them into an oracle table with column as external BLOB. Since the contents are so heavy for each objects , using XMLTYPE column is not feasible.
    The xml files comes as either java hash_map or string which i have to pass as parameter to an Oracle stored procedure which stores as external BLOB in OS through a table.
    My first doubt is this the correct approach.
    My second doubt here is how to interpret java hash_map object within PLSQL when it is passed to it.
    Apologies if the question is silly since i am a new comer to java.
    Thanks in advance ,
    Vijay G

    vijay S P G wrote:
    If i have plsql collection with a varchar2 and a blob as record type then can i directly pass the java hash map to the procedure having parameter datatype as the above said record type ?Of course not. Obviously the first reason for that is because the "blob" needs to be a file path and not a blob.
    Second reason is no databases that I know of take a hash data type. Some take arrays. But I doubt that is worth the trouble.
    You have a collection of name value (path) pairs. Iterate over the collection and for each name do an insert of the name and path.

  • Pl sql join and selecting columns from join."t"."c": invalid at debug time

    I noticed the error at cc.Country that is shown because cc is not yet there at compile time (got that
    from searching this forum).
    Isnt that a bit weak of oracle sql developer that it doesnt compile from the outside to the inside /core but
    rather form top to bottom?
    Am I right with my conclusion? If so, how to do it otherwise i.e. specifying that cc.country is
    a column from countrycodes joined with table6 ?
    SELECT DISTINCT 0,
    2,
    SUBSTR('metable', 0, 1) || '_ABC',
    'ABC_' || 'metable',
    'ABC ' ||cc.Country ,
    '+'
    FROM table6
    LEFT JOIN COUNTRYCODE cc
    ON cc.Code = metable
    WHERE metable IS NOT NULL
    AND metable <> ''

    metalray wrote:
    hi Boneist
    thanks for your reply
    its in a plsql procedure (10g). well as you see cc is the alias
    of the table COUNTRYCODE. which does exists. the error is at 'ABC ' ||cc.Country'
    telling me"PL/SQL: ORA-01747: invalid user.table.column,..."
    when I put COUNTRYCODE next to table6 in the FROM it works but thats not what I want
    since I want to join both tables not just select from both.Can you give us your exact code and exact error message.
    I'm not finding any problem with using alias names in the query..
    SQL> select d.dname
      2        ,'EMPNAME : '||e.ename
      3  from dept d LEFT JOIN emp e ON e.deptno = d.deptno;
    DNAME          'EMPNAME:'||E.ENAME
    RESEARCH       EMPNAME : SMITH
    SALES          EMPNAME : ALLEN
    SALES          EMPNAME : WARD
    RESEARCH       EMPNAME : JONES
    SALES          EMPNAME : MARTIN
    SALES          EMPNAME : BLAKE
    ACCOUNTING     EMPNAME : CLARK
    RESEARCH       EMPNAME : SCOTT
    ACCOUNTING     EMPNAME : KING
    SALES          EMPNAME : TURNER
    RESEARCH       EMPNAME : ADAMS
    SALES          EMPNAME : JAMES
    RESEARCH       EMPNAME : FORD
    ACCOUNTING     EMPNAME : MILLER
    OPERATIONS     EMPNAME :
    15 rows selected.
    SQL>

  • How to implement a linked list in oracle ?

    HI All
    I want to know if there a way to implement a linked list in oracle ?
    Thanks in Advanced
    Naama

    A linked list is an array of the relevant data plus an indicator of the next and previous entries, right?
    Sounds easily achievable with any of the plsql collection types.
    The simplest would be a plsql associative array of a record
    Assignments of records in collections is always a bit hamfisted compared to sql objects types though (IMO).
    Something like ?
    DECLARE
    TYPE r_payload IS RECORD
    (col1 number,
      col2 number);
    TYPE r_array_entry is RECORD
    (prev_entry PLS_INTEGER,
      next_entry PLS_INTEGER,
      payload    r_payload);
    TYPE t_array IS TABLE OF r_array_entry INDEX BY PLS_INTEGER;
    v_array t_array;
    BEGIN
    NULL;
    END; 
      The use case for such a structure in properly coded SQL & PL/SQL is possibly the harder question.

Maybe you are looking for

  • Changing the default event time to all-day in Month View?

    I updated to Mavericks today, and when I went to add an event to my Calendar, I discovered that all-day was not the default time.  In Mountain Lion, when going to add an event in Month View, it was automatically set to all-day, which is perfect becau

  • Resolve internet address from IF_RECIPIENT_BCS?

    Hello, i use the CL_BCS=>SHORT_MESSAGE function for sending an object linked to a mail. Afterwards I have to resolve and to document the recipient adresses in plain text. There are several types of adresses like user names and internet adresses. I am

  • Default Activities in Routing

    Hi Friends, We have assigned activities with work centers, but after creating routing and we are not getting the activities in routing therefrore in CK11N, we are not getting these activities. Please suggest how can we get the activity in routing. Kr

  • Copying DC's from Sandbox to Development Environment - How to ?

    Hi I am using SandBox development environment for creating WebDynpro DC projects.Now how to copy existing DC projects to the actual Development environment. I have tried to export the project but the DC Metadata folder is not adding to the .zip file.

  • How do i create a favourites website list (i'm new to mac)

    I have used a PC for the last 8 years and am new to mac. How do I create a favourites list of websites I commomnly visit?