Problem in table(cast(

i have two collection variables v1_coll and v2_coll(both are of same table type 'tt_coll' and 'rt_coll' is a record type)
tt_coll  is table of  rt_coll;
v1_coll    tt_coll := tt_coll();
v2_coll    tt_coll := tt_coll();
now i am populating the v1_coll through a select clause..
select ......... from table1, table2, table3 into v_coll1 where <lots of joins>;
now i want to populate the second collection v_coll2 from the first collection.
i dont want to make a for loop assigning each and every row of the first collection into the second..
so i table cast the first collection and do a select on that into the second...
select ......... into v2_coll from table(cast(v_coll1 as tt_coll));
but it is failing......please help me...

Note that you can use bulk collect to select into a local collection type, and to assign each and every row of the first collection to the second you can just use v2_coll := v1_coll
declare
type tt_coll is table of emp%rowtype;
v1_coll tt_coll := tt_coll();
v2_coll tt_coll := tt_coll();
begin
  select * bulk collect into v1_coll from emp where ename like 'S%';
  dbms_output.put_line('rows returned = '||to_char(SQL%ROWCOUNT));
  v2_coll := v1_coll;
  dbms_output.put_line('v2_col1(1).ename = '||v2_coll(1).ename);
  v2_coll(1).ename := 'JONES';
  dbms_output.put_line('v2_col1(1).ename = '||v2_coll(1).ename);
  dbms_output.put_line('v1_col1(1).ename = '||v1_coll(1).ename);
end;
rows returned = 2
v2_col1(1).ename = SMITH
v2_col1(1).ename = JONES
v1_col1(1).ename = SMITHRegards,
Bob

Similar Messages

  • What this problem? table(cast(array))

    exits in databse one type
    " type InNumberTab is table of number;"
    declare
    v_tbseq_trans:= InNumberTab(null);
    select count(*) into v_cont
    from dados_propriedade dp
    where dp.num_pessoa=p_num_pessoa
    group by num_nirf;
    v_tbseq_trans.EXTEND(SQL%ROWCOUNT);
    v_cont:=0;
    for v_cs in
    (select to_number(replace(dp.num_nirf,'-','')) nirf, max(dp.seq_transacao) seq_transacao
    from dados_propriedade dp
    where dp.num_pessoa=p_num_pessoa
    group by dp.num_nirf) loop
    v_tbseq_trans(v_cont):=v_cs.seq_transacao;
    v_cont:=v_cont+1;
    END LOOP;
    open p_cursor_prop for
    select
    from dados_propriedade dp
    where dp.seq_transacao in (SELECT column_value FROM TABLE(CAST(v_tbseq_trans as InNumberTab)));

    I'll try to guess what you mean.
    If you need to use object or collection type in SQL query you should declare in in SQL server not in PL/SQL code:
    SQL> declare
      2   type na is table of number;
      3   nat na := na(1,2,3);
      4  begin
      5   for x in (select column_value y from table(cast(nat as na))) loop
      6     dbms_output.put_line(x.y);
      7   end loop;
      8  end;
      9  /
    for x in (select column_value y from table(cast(nat as na))) loop
    ERROR at line 5:
    ORA-06550: line 5, column 56:
    PL/SQL: ORA-00902: invalid datatype
    ORA-06550: line 5, column 11:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 6, column 25:
    PLS-00364: loop index variable 'X' use is invalid
    ORA-06550: line 6, column 4:
    PL/SQL: Statement ignored
    SQL> set serveroutput on
    SQL> create type na is table of number;
      2  /
    Type created.
    SQL> declare
      2   nat na := na(1,2,3);
      3  begin
      4   for x in (select column_value y from table(cast(nat as na))) loop
      5     dbms_output.put_line(x.y);
      6   end loop;
      7  end;
      8  /
    1
    2
    3
    PL/SQL procedure successfully completed.Is it your problem ?
    Rgds.

  • Problem with table(cast..)) clause - timeout

    Hello,
    I've in shared memory one query in multiple copies - one differences between copies is in arguments count given with in clause. For example, in shared memory i have:
    select name from a where id in (?);
    select name from a where id in (?,?);
    select name from a where id in (?,?,?);
    I try to minimize size of shared memory by change this query as in example:
    select name from a where id in (select * from table(cast(? as seqintegertable)))
    In this case my shared memory is ok, but I have problem with timeout exception:
    - time of executing query without cast is about 250 ms
    - with cast: about 10560 ms and sometimes I get ORA-01652
    Why this time is so long? Can I reduce it? Maybe I should change something other?

    user13241971 wrote:
    Why this time is so long? Can I reduce it? Maybe I should change something other?To know why your query takes so long: {thread:id=501834}
    Likely it's because of wrong cardinalities, to which this excellent article gives possible solutions: http://www.oracle-developer.net/display.php?id=427
    Regards,
    Rob.

  • Problems using table (cast as)

    Hi
    I have some code like this:
    declare
    TYPE t_forall_bags IS TABLE OF misbag.bags%ROWTYPE;
    l_forall_bags t_forall_bags := t_forall_bags ();
    begin
    open c2;
    FETCH c2 BULK COLLECT INTO l_forall_bags LIMIT v_array_size;
    if l_forall_bags.COUNT > 0 then
    begin
    merge into misbag.bags dest
    using (select col1,
    col2,
    colx
    from TABLE( cast( l_forall_bags as t_forall_bags ) ) ) src
    on (dest.bag_id = src.bag_id )
    when matched then
    --do update stuff
    when not matched then
    --do insert stuff;
    end;
    end if;
    end;
    on compilation I am getting an ora-00902 invalid datatype seemingly on the t_forall_bags in side the cast (as highlighted in bold)
    I thought I had the syntax correct, but maybe not.
    rgds
    Tony

    BluShadow wrote:Why are you querying data from the database into a collection (in expensive PGA memory) to then pass that back down to the SQL engine to be treated as a table (and incidently one without any indexes or the other benefits of a database table).Well that is a very good question.
    The task is to take a generally smaller number of very recent rows from one table and apply them to a similar table in another schema. This task will run very frequently (ie every second or two) so generally will have a smallish number fo rows (ie 100-200) each time it runs. Some rows are updates and some rows are inserts.
    If there is a delay on running the task, we don't necessarily want to process all of the outstanding rows in one go, but to take them in chunks until is catches up.
    One way to do this would be to perform multiple queries on the original data to check how many rows where outstanding, then to select which ones were to be merged, then go ahead and do the merge (with both main tables as you propose). This alternate idea (that I was looking at here) was to bulk collect the first n rows from the table into the array (up to the defined limit) and then to merge this list of rows into the destination table. The goal was to perform fewer data accesses and make the process least expensive in I/O. By bulk selecting up to N rows into the array, it was felt that there was less I/O on the source table, and probably the same amount of I/O on the destination table.
    The very first method of writing was to bulk select the first N rows into an array, delete any that already existed in the dest table then to "forall" insert the array contents into the destination table. This seemed to work quite well, we wanted to compare the merge version and see how it compared in speed and I/O usage.
    Tony
    rgds
    Tony

  • 10gr2 TABLE(CAST( problem

    We have an existing report that uses existing function to table cast back data in the from clause. A very simplified example:
    FROM grant g, grantparticipant gt, table(cast(getSchedule(g.grant_pk, gt.grantparticipant_pk) as r_sched)) sched
    where g.grant_pk = gt.grant_fk
    and sched.grantparticipant_pk = gt.grantparticipant_pk
    The grantparticipant_pk is NULL when captured in the function. There are no null values in the table (it's a primary key). When the where clause is changed to reference a specific pk it works fine and the value is filled in.
    The works in our production db where the Oracle version is 10g. It works in development which is also 10g. The problem only appears to be with our 10gr2 DB.
    Any ideas....

    The problem was solved with ANSI JOINs. Would still like to know why that problem occurred?

  • Table(cast  - invalid datatype problem

    Hi All,
    Basic scenario:
    PACKAGE
    create or replace
    PACKAGE C2_PAYMENT_DOC IS
    TYPE bin_array IS TABLE OF NUMBER
    INDEX BY BINARY_INTEGER;
    FUNCTION test_fun(l_doc_id IN integer) RETURN bin_array;
    PACKAGE_BODY
    create or replace
    package body C2_PAYMENT_DOC as
    FUNCTION test_fun (l_doc_id IN integer) RETURN bin_array IS
    l_gross bin_array;
    begin
    c2_purchase_invoice.get_inv_gross_amount(l_doc_id, l_gross(1));
    return l_gross;
    end;
    END;
    QUERY
    select * from Table(Cast(c2_payment_doc.test_fun(1) As bin_array));
    Result of the query is ORA-00902: invalid datatype
    How can I make the select statement valid?
    Thanks in advance,
    Bartek

    You can not use local collection types in SQL. You must create type bin_array as SQL nested table type. Also, depending on version you might not need to cast:
    SQL> CREATE OR REPLACE
      2    TYPE bin_array
      3      AS TABLE OF NUMBER
      4  /
    Type created.
    SQL>  create or replace
      2   PACKAGE C2_PAYMENT_DOC IS
      3  FUNCTION test_fun(l_doc_id IN integer) RETURN bin_array;
      4  end;
      5  /
    Package created.
    SQL> create or replace
      2  package body C2_PAYMENT_DOC as
      3 
      4  FUNCTION test_fun (l_doc_id IN integer) RETURN bin_array IS
      5  l_gross bin_array := bin_array();
      6  begin
      7      l_gross.extend;
      8      l_gross(1) := l_doc_id;
      9  return l_gross;
    10  end;
    11  END;
    12  /
    Package body created.
    SQL> select * from Table(Cast(c2_payment_doc.test_fun(1) As bin_array));
    COLUMN_VALUE
               1
    SQL> select * from Table(c2_payment_doc.test_fun(1))
      2  /
    COLUMN_VALUE
               1
    SQL> SY.

  • Problem with Table Function in ver. 8.1.7.0

    Hello,
    I have a Problem using a Table Function in Oracle version 8.1.7.0:
    type TTest_Object is Object
    MSG_TRACKID VARCHAR2(25)
    type TTest_Table is Table of TTest_Object;
    function Test_Function return TTest_Table is
    Result TTest_Table;
    TmpObj TTest_Object := TTest_Object( null );
    begin
    TmpObj.MSG_TRACKID := '00001';
    Result := TTest_Table( TmpObj );
    return(Result);
    end Test_Function;
    when i do:
    declare
    Type TTmpRecord is Record (MSG_TRACKID varchar2(25));
    Type TC is Ref Cursor Return TTmpRecord;
    C1 TC;
    TmpObj VarChar2(25);
    TmpTable TTest_Table;
    begin
    TmpTable := Test_Function;
    open C1 for Select * FROM TABLE(CAST(TmpTable as TTest_Table));
    loop
    fetch C1 into TmpObj;
    exit when C1%notfound;
    DBMS_OUTPUT.PUT_LINE(TmpObj);
    end loop;
    close C1;
    end;
    it works fine!
    but, when i do:
    "Select * From TABLE(CAST(Test_Function as TTest_Table))"
    i get a: "ORA-000904: Invalid Column Name"
    if i do the Select in version 8.1.7.4 it works fine...
    does anyone know a work around in version 8.1.7.0?

    export from a lower version to import in higher ver is ok.
    Please see metalink doc 132904.1 for exp/imp compatiblty matrix.

  • TABLE(CAST()) function not returning the correct results in few scenarios.

    I am using TABLE(CAST()) operation in PL/SQL and it is returning me no data.
    Here is what I have done:
    1.     Created Record type
    CREATE OR REPLACE TYPE target_rec AS OBJECT
    target__id          NUMBER(10),
    target_entity_id NUMBER(10),
    dd           CHAR(3),
    fd           CHAR(3),
    code      NUMBER(10),
    target_pct      NUMBER,
    template_nm VARCHAR2(50),
    p_symbol      VARCHAR2(10),
    pm_init          VARCHAR2(3),
    target_name     VARCHAR2(20),
    targe_type     VARCHAR2(30),
    target_caption     VARCHAR2(30),
    sort_order      NUMBER (4)
    2.     Created Table type
    CREATE OR REPLACE TYPE target_arr AS TABLE OF target_rec
    3.     Created Stored procedure which accepts parameter of type target_arr and runs the Table(Cast()) function on it.
         Following is the simplified form of my procedure.
         PROCEDURE get_target_weights
         p_in_template_target IN target_arr,
         p_out_count          OUT NUMBER,
         IS
         BEGIN
              SELECT count(*) into p_out_count
         FROM TABLE(CAST(p_in_template_target AS                     target_arr)) arr;
         END;
    I am calling get_target_weights from my java code and passing p_in_template_target with 10140 records.
    Scenario 1: If target_pct in the last record is 0, p_out_count returned from the procedure is 0.
    Scenario 2: If target_pct in the last record is any other value(say 0.01), p_out_count returned from the procedure is 10140.
    Please help me understand why the Table(Cast()) is not returning the correct results in Scenario 1. Also adding or deleting any record from the test data returns the correct results (i.e. if keep target_pct in the last record as 0 but add or delete any record).
    Let me know how can I attach the test data I am using to help you debugging as I don’t see any Attach file button on Post Message screen on the forum.

    I am not able to reproduce this problem with a small data set. I can only reproduce with the data having 10140 records.
    I am not sure if this is the memory issue as adding a new record also solves the problem.
    This should not be the error because of wrong way of filling the records in java as for testing purpose I just saved the records which I am sending from java in a table. I updated the stored procedure as well to read the data from the table and then perform TABLE(CAST()) operation. I am still getting 0 as the output for scenario 1 mentioned in my last mail.
    Here is what I have updated:
    1.     Created the table target_table
    CREATE Table target_table
    target_id          NUMBER(10),
    target_entity_id NUMBER(10),
    dd           CHAR(3),
    fd           CHAR(3),
    code      NUMBER(10),
    target_pct      NUMBER,
    template_nm VARCHAR2(50),
    p_symbol      VARCHAR2(10),
    pm_init          VARCHAR2(3),
    target_name     VARCHAR2(20),
    target_type     VARCHAR2(30),
    target_caption     VARCHAR2(30),
    sort_order      NUMBER (4)
    2.     Inserted data into the table : The script has around 10140 rows. Pls let me know how can I send it to you
    3.     Updated procedure to read data from table and stored into variable of type target_arr. Run Table(cast()) operation on target_arr and get the count
    PROCEDURE test_target_weights
    IS
         v_target_rec target_table%ROWTYPE;
         CURSOR wt_cursor IS
         Select * from target_table;
         v_count NUMBER := 1;
         v_target_arr cws_target_arr:= target_arr ();
         v_target_arr_rec target_rec;
         v_rec_count NUMBER;
         BEGIN
         OPEN wt_cursor;
         loop
              fetch wt_cursor into v_target_rec; -- fetch data from table into local           record.
              exit when wt_cursor%notfound;
              --move data into target_arr
              v_target_arr_rec :=                     cws_curr_pair_entity_wt_rec(v_target_rec target_id,v_target_rec. target_entity_id,
                        v_target_rec.dd,v_target_rec.fd,v_target_rec.code,v_target_rec.target_pct,
         v_target_rec.template_nm,v_target_rec.p_symbol,v_target_rec.pm_init,v_target_rec.template_name,
         v_target_rec.template_type,v_target_rec.template_caption,v_target_rec.sort_order);
              v_target_arr.extend();
              v_target_arr(v_count) := v_target_arr_rec;
              v_count := v_count + 1;
         end loop;
         close wt_cursor;
         -- run table cast on target_arr
         SELECT count(*) into v_rec_count
         FROM TABLE(CAST(v_target_arr AS target_arr)) arr;
         DBMS_OUTPUT.enable;
         DBMS_OUTPUT.PUT_LINE('p_out_count ' || v_rec_count);
         DBMS_OUTPUT.PUT_LINE('v_count ' || v_count);
    END;
    Output is
    p_out_count 0
    v_count 10140
    Expected output
    p_out_count 10140
    v_count 10140

  • Ora-1460 during select using table(cast(type))

    Hi all!
    I've got a problem with a query that fails with a ora-1460 at random time intervals. This is a 10.2.0.3 version database running on a sun os.
    We've managed to reproduce this error controlled when running an analyze on the table in question at the same time this query runs.
    The error looks like this:
    Unexpected system error, see server log for details. Root message is: org.apache.ojb.broker.PersistenceBrokerSQLException: * SQLException during execution of sql-statement: * sql statement was 'SELECT A0.ID,A0.LOCK_VERSION,A0.CLASS_NAME,A0.DESCRIPTION,A0.NAME,A0.EXTERNAL_ID,A0.ORDER_NUMBER,A0.LEVEL_ID,A0.ROOT_AH_ID,A0.DIFF_END_DATE,A0.DIFF_START_DATE,A0.SUPPORTED_BY_ASS_CAL,A0.CATEGORY_ROLE_ID FROM CATEGORY A0 WHERE A0.ID IN (select /*+ cardinality(1) */ * from table(cast( ems_string_to_table(?) as ems_table_of_number_type ))union select /*+ cardinality(1) */ * from table(cast( ems_string_to_table('') as ems_table_of_number_type)))' * Exception message is [ORA-01460: unimplemented or unreasonable conversion requested ] * Vendor error code [1460] * SQL state code [72000]
    ems_string_to_table is a function thats populates a type with a unknown number of values. Though, the length of the string never exceeds 4k.
    ems_table_of_number_type is a type define as "table of numbers".
    Has anybody seen this error before, or have any idea why this should be?
    Best regards,
    Heyers

    There is an IN clause constaraint i.e max number of characters you can pass from Oracle .Please check your select inner query which might be resulting to cross more than the boundary IN clause ,

  • Derive found flag in SQL with where clause using TABLE(CAST function

    Dear All,
    Stored procedure listEmployees
    ==========================
    CREATE OR REPLACE TYPE STRING_ARRAY AS VARRAY(8000) OF VARCHAR2(15);
    empIdList STRING_ARRAY
    countriesList STRING_ARRAY
    SELECT EMP_ID, EMP_COUNTRY, EMP_NAME, FOUND_FLAG_
    FROM EMPLOYEE WHERE
    EMP_ID IN
    (SELECT * FROM TABLE(CAST(empIdList AS STRING_ARRAY))
    AND EMP_COUNTRY IN
    (SELECT * FROM TABLE(CAST(countriesList AS STRING_ARRAY))
    =================
    I have a stored procedure which lists the employees using above simple query.
    Here I am using table CAST function to find the list of employees in one go
    instead of looping through each and every employee
    Everything fine until requirements forced me to get the FOUND_FLAG as well.
    Now I wanted derive the FOUND_FLAG by using rownum, rowid, decode functions
    but I was not successful
    Can you please suggest if there is any intelligent way to say weather the
    row is found for given parameters in the where clause?
    If not I may have to loop through each set of empIdList, countriesList
    and find the values individually just to set a flag. In this approach I can’t use
    the TABLE CAST function which is efficient I suppose.
    Note that query STRING_ARRAY is an VARRAY. It is very big in size and this procedure
    suppose to handle large sets of data.
    Thanks In advance
    Regards
    Charan
    Edited by: kmcharan on 03-Dec-2009 09:55
    Edited by: kmcharan on 03-Dec-2009 09:55

    If your query returns results, you have found them... so your "FOUND" flag might be a constant,...

  • Problem with table formatting

    I'm having a lot of problems with tables not reflecting their formatting when I open them in a browser. I've tried opening in Safari, Firefox & Camino with the same results. For example, a row with the following html content has a much larger height & aligns the text to the top when opened in a browser:
    <tr>
              <td height="15" colspan="3" valign="middle"><h6 align="center">Summer 2009</h6>
              </td>
            </tr>
    If it matters, this is a row in a table nested in another table. Here's the code down to the row in question (all tags are closed properly in the remaining code):
    <table width="600" border="2" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td align="center" valign="top"><img src="images/events.jpg" width="250" height="35"></td>
        </tr>
        <tr>
          <td align="left" valign="top">
          <table width="100%" border="0" align="center" cellpadding="1" cellspacing="0">
            <tr>
              <td height="15" colspan="3" valign="middle"><h6 align="center">Summer 2009</h6>
              </td>
            </tr>
    I am using a style sheet for text. Here's the code for "h6" if that matters:
    h6 {
    font-family: Verdana, Geneva, Arial;
    font-size: 14px;
    font-weight: bold;
    color: #660099;
    Any ideas is appreciated. This is driving me nuts. Spacing and alignment sometimes work and sometimes don't work. Dreamweaver is supposed to make such things easier!
    Kevin

    Header tags are usually used round a bit of text, not parts of a table, and if you don't specify the margins on them, can force different amounts of space below in different browsers. Try making the bottom margin on h6 zero, and confine it to text within a cell.
    Also, if you can upload your page somewhere and let us have the url it will be easier to troubleshoot.

  • Problem in Table maintenance view

    Hi all,
    i am getting some problem in table maintenance view.
    In my table i have some fields and when i created my table maintenance view , it is created , but when i try  to see it in SM30 its not showing my fields and even i am unable to create a  new entry. when i click
    new entries its going back to the sm30 screen..
    How to go abt it
    please help me

    Hello,
    Have you created the table maintanence view the right way.
    You can get good help from below link: [[http://www.****************/Tutorials/ABAP/TableMaintenance/demo.htm]]
    Also, please check the Delivery Class and Data Browser/Table View Maint. in the Delivery and Maintanence tab of the table.
    Thanks,
    Jayant
    Edited by: Jayant Sahu on Nov 24, 2008 3:00 PM

  • Error in table(Cast)

    Hi
    I tried the following code
    could you please resolve the error in this code
    create or replace type numlist as table of number;
    declare
      var numlist;
    begin
    select 1 into var
      from table(cast(var));
    end;
    /thanks

    ME_XE?create or replace type numlist as table of number;
      2  /
    Type created.
    Elapsed: 00:00:00.62
    ME_XE?
    ME_XE?declare
      2    var    numlist  := numlist(1,2,3);
      3  begin
      4
      5     for x in
      6     (
      7        select column_value
      8        from table(cast(var as numlist))
      9     )
    10     loop
    11        dbms_output.put_line('value = ' || x.column_value);
    12     end loop;
    13
    14  end;
    15  /
    value = 1
    value = 2
    value = 3
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.46

  • 10g: parallel pipelined table func. using table(cast(SQL collect.))?

    Hi,
    i try to distribute SQL data objects - stored in a SQL data type TABLE OF <object-Type> - to multiple (parallel) instances of a table function,
    by passing a CURSOR(...) to the table function, which selects from the SQL TABLE OF storage via "select * from TABLE(CAST(<storage> as <storage-type>)".
    But oracle always only uses a single table function instance :-(
    whatever hints i provide or setting i use for the parallel table function (parallel_enable ...)
    Could it be, that this is due to the fact, that my data are not
    globally available, but only in the main thread data?
    Can someone confirm, that it's not possible to start multiple parallel table functions
    for selecting on SQL data type TABLE OF <object>storages?
    Here's an example sqlplus program to show the issue:
    -------------------- snip ---------------------------------------------
    set serveroutput on;
    drop table test_table;
    drop type ton_t;
    drop type test_list;
    drop type test_obj;
    create table test_table
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_obj as object(
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_list as table of test_obj;
    create or replace type ton_t as table of number;
    create or replace package test_pkg
    as
         type test_rec is record (
              a number(19,0),
              b timestamp with time zone,
              c varchar2(256)
         type test_tab is table of test_rec;
         type test_cur is ref cursor return test_rec;
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a));
    end;
    create or replace package body test_pkg
    as
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a))
    is
              sid number;
              counter number(19,0) := 0;
              myrec test_rec;
              mytab test_tab;
              mytab2 test_list := test_list();
         begin
              select userenv('SID') into sid from dual;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): enter');
              loop
                   fetch mycur into myRec;
                   exit when mycur%NOTFOUND;
                   mytab2.extend;
                   mytab2(mytab2.last) := test_obj(myRec.a, myRec.b, myRec.c);
              end loop;
              for i in mytab2.first..mytab2.last loop
                   -- attention: saves own SID in test_obj.a for indication to caller
                   --     how many sids have been involved
                   pipe row(test_obj(sid, mytab2(i).b, mytab2(i).c));
                   counter := counter + 1;
              end loop;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): exit, piped #' || counter || ' records');
         end;
    end;
    declare
         myList test_list := test_list();
         myList2 test_list := test_list();
         sids ton_t := ton_t();
    begin
         for i in 1..10000 loop
              myList.extend; myList(myList.last) := test_obj(i, sysdate, to_char(i+2));
         end loop;
         -- save into the real table
         insert into test_table select * from table(cast (myList as test_list));
         dbms_output.put_line(chr(10) || 'copy ''mylist'' to ''mylist2'' by streaming via table function...');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from table(cast (myList as test_list)) tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
         dbms_output.put_line(chr(10) || 'copy physical ''test_table'' to ''mylist2'' by streaming via table function:');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from test_table tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
    end;
    -------------------- snap ---------------------------------------------
    Here's the output:
    -------------------- snip ---------------------------------------------
    copy 'mylist' to 'mylist2' by streaming via table function...
    test_pkg.TF( sid => '98' ): enter
    test_pkg.TF( sid => '98' ): exit, piped #10000 records
    ... saved #10000 records
    worker thread's sid list:
    sid #98 -- ONLY A SINGLE SID HERE!
    copy physical 'test_table' to 'mylist2' by streaming via table function:
    ... saved #10000 records
    worker thread's sid list:
    sid #128 -- A LIST OF SIDS HERE!
    sid #141
    sid #85
    sid #125
    sid #254
    sid #101
    sid #124
    sid #109
    sid #142
    sid #92
    PL/SQL procedure successfully completed.
    -------------------- snap ---------------------------------------------
    I posted it to newsgroup comp.databases.oracle.server.
    (summary: "10g: parallel pipelined table functions with cursor selecting from table(cast(SQL collection)) doesn't work ")
    But i didn't get a response.
    There i also wrote some background information about my application:
    -------------------- snip ---------------------------------------------
    My application has a #2 steps/stages data selection.
    A 1st select for minimal context base data
    - mainly to evaluate for due driving data records.
    And a 2nd select for all the "real" data to process a context
    (joining much more other tables here, which i don't want to do for non-due records).
    So it's doing stage #1 select first, then stage #2 select - based on stage #1 results - next.
    The first implementation of the application did the stage #1 select in the main session of the pl/sql code.
    And for the stage #2 select there was done a dispatch to multiple parallel table functions (in multiple worker sessions) for the "real work".
    That worked.
    However there was a flaw:
    Between records from stage #1 selection and records from stage #2 selection there is a 1:n relation (via key / foreign key relation).
    Means, for #1 resulting record from stage #1 selection, there are #x records from stage #2 selection.
    That forced me to use "cluster curStage2 by (theKey)".
    Because the worker sessions need to evaluate the all-over status for a context of #1 record from stage #1 and #x records from stage #2
    (so it needs to have #x records of stage #2 together).
    This then resulted in delay for starting up the worker sessions (i didn't find a way to get rid of this).
    So i wanted to shift the invocation of the worker sessions to the stage #1 selection.
    Then i don't need the "cluster curStage2 by (theKey)" anymore!
    But: i also need to do an update of the primary driving data!
    So the stage #1 select is a 'select ... for update ...'.
    But you can't use such in CURSOR for table functions (which i can understand, why it's not possible).
    So i have to do my stage #1 selection in two steps:
    1. 'select for update' by main session and collect result in SQL collection.
    2. pass collected data to parallel table functions
    And for 2. i recognized, that it doesn't start up multiple parallel table function instances.
    As a work-around
    - if it's just not possible to start multiple parallel pipelined table functions for dispatching from 'select * from TABLE(CAST(... as ...))' -
    i need to select again on the base tables - driven by the SQL collection data.
    But before i do so, i wanted to verify, if it's really not possible.
    Maybe i just miss a special oracle hint or whatever you can get "out of another box" :-)
    -------------------- snap ---------------------------------------------
    - many thanks!
    rgds,
    Frank

    Hi,
    i try to distribute SQL data objects - stored in a SQL data type TABLE OF <object-Type> - to multiple (parallel) instances of a table function,
    by passing a CURSOR(...) to the table function, which selects from the SQL TABLE OF storage via "select * from TABLE(CAST(<storage> as <storage-type>)".
    But oracle always only uses a single table function instance :-(
    whatever hints i provide or setting i use for the parallel table function (parallel_enable ...)
    Could it be, that this is due to the fact, that my data are not
    globally available, but only in the main thread data?
    Can someone confirm, that it's not possible to start multiple parallel table functions
    for selecting on SQL data type TABLE OF <object>storages?
    Here's an example sqlplus program to show the issue:
    -------------------- snip ---------------------------------------------
    set serveroutput on;
    drop table test_table;
    drop type ton_t;
    drop type test_list;
    drop type test_obj;
    create table test_table
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_obj as object(
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_list as table of test_obj;
    create or replace type ton_t as table of number;
    create or replace package test_pkg
    as
         type test_rec is record (
              a number(19,0),
              b timestamp with time zone,
              c varchar2(256)
         type test_tab is table of test_rec;
         type test_cur is ref cursor return test_rec;
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a));
    end;
    create or replace package body test_pkg
    as
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a))
    is
              sid number;
              counter number(19,0) := 0;
              myrec test_rec;
              mytab test_tab;
              mytab2 test_list := test_list();
         begin
              select userenv('SID') into sid from dual;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): enter');
              loop
                   fetch mycur into myRec;
                   exit when mycur%NOTFOUND;
                   mytab2.extend;
                   mytab2(mytab2.last) := test_obj(myRec.a, myRec.b, myRec.c);
              end loop;
              for i in mytab2.first..mytab2.last loop
                   -- attention: saves own SID in test_obj.a for indication to caller
                   --     how many sids have been involved
                   pipe row(test_obj(sid, mytab2(i).b, mytab2(i).c));
                   counter := counter + 1;
              end loop;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): exit, piped #' || counter || ' records');
         end;
    end;
    declare
         myList test_list := test_list();
         myList2 test_list := test_list();
         sids ton_t := ton_t();
    begin
         for i in 1..10000 loop
              myList.extend; myList(myList.last) := test_obj(i, sysdate, to_char(i+2));
         end loop;
         -- save into the real table
         insert into test_table select * from table(cast (myList as test_list));
         dbms_output.put_line(chr(10) || 'copy ''mylist'' to ''mylist2'' by streaming via table function...');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from table(cast (myList as test_list)) tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
         dbms_output.put_line(chr(10) || 'copy physical ''test_table'' to ''mylist2'' by streaming via table function:');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from test_table tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
    end;
    -------------------- snap ---------------------------------------------
    Here's the output:
    -------------------- snip ---------------------------------------------
    copy 'mylist' to 'mylist2' by streaming via table function...
    test_pkg.TF( sid => '98' ): enter
    test_pkg.TF( sid => '98' ): exit, piped #10000 records
    ... saved #10000 records
    worker thread's sid list:
    sid #98 -- ONLY A SINGLE SID HERE!
    copy physical 'test_table' to 'mylist2' by streaming via table function:
    ... saved #10000 records
    worker thread's sid list:
    sid #128 -- A LIST OF SIDS HERE!
    sid #141
    sid #85
    sid #125
    sid #254
    sid #101
    sid #124
    sid #109
    sid #142
    sid #92
    PL/SQL procedure successfully completed.
    -------------------- snap ---------------------------------------------
    I posted it to newsgroup comp.databases.oracle.server.
    (summary: "10g: parallel pipelined table functions with cursor selecting from table(cast(SQL collection)) doesn't work ")
    But i didn't get a response.
    There i also wrote some background information about my application:
    -------------------- snip ---------------------------------------------
    My application has a #2 steps/stages data selection.
    A 1st select for minimal context base data
    - mainly to evaluate for due driving data records.
    And a 2nd select for all the "real" data to process a context
    (joining much more other tables here, which i don't want to do for non-due records).
    So it's doing stage #1 select first, then stage #2 select - based on stage #1 results - next.
    The first implementation of the application did the stage #1 select in the main session of the pl/sql code.
    And for the stage #2 select there was done a dispatch to multiple parallel table functions (in multiple worker sessions) for the "real work".
    That worked.
    However there was a flaw:
    Between records from stage #1 selection and records from stage #2 selection there is a 1:n relation (via key / foreign key relation).
    Means, for #1 resulting record from stage #1 selection, there are #x records from stage #2 selection.
    That forced me to use "cluster curStage2 by (theKey)".
    Because the worker sessions need to evaluate the all-over status for a context of #1 record from stage #1 and #x records from stage #2
    (so it needs to have #x records of stage #2 together).
    This then resulted in delay for starting up the worker sessions (i didn't find a way to get rid of this).
    So i wanted to shift the invocation of the worker sessions to the stage #1 selection.
    Then i don't need the "cluster curStage2 by (theKey)" anymore!
    But: i also need to do an update of the primary driving data!
    So the stage #1 select is a 'select ... for update ...'.
    But you can't use such in CURSOR for table functions (which i can understand, why it's not possible).
    So i have to do my stage #1 selection in two steps:
    1. 'select for update' by main session and collect result in SQL collection.
    2. pass collected data to parallel table functions
    And for 2. i recognized, that it doesn't start up multiple parallel table function instances.
    As a work-around
    - if it's just not possible to start multiple parallel pipelined table functions for dispatching from 'select * from TABLE(CAST(... as ...))' -
    i need to select again on the base tables - driven by the SQL collection data.
    But before i do so, i wanted to verify, if it's really not possible.
    Maybe i just miss a special oracle hint or whatever you can get "out of another box" :-)
    -------------------- snap ---------------------------------------------
    - many thanks!
    rgds,
    Frank

  • Table(cast())

    Hi All,
    I am using Oracle 9i and I have an Oracle Type which has been created as follows
    create or replace TYPE "Dummy" AS VARRAY (500) OF VARCHAR2(50)
    It is assigned a set of values as follows:
    oracle.sql.ArrayDescriptor desc = oracle.sql.ArrayDescriptor.createDescriptor("Dummy", stmt.getConnection());
    oracle.sql.ARRAY newArray;
    newArray = new oracle.sql.ARRAY(desc, stmt.getConnection() , filter); //where filter contains the values here
    I am trying to execute the following statement but I get an error.
    SELECT process_instance_id, workstep_name, status FROM WORKSTEP
    WHERE PROCESS_INSTANCE_ID IN table(cast(newarray)))
    AND WORKSTEP_NAME = 'X';
    When I execute this I get a ORA-00936: missing expression
    Can you pls point out what's wrong here and how I can cast a varray as a table and use it in an "IN" clause?
    Thanks in advance.
    AD.

    user604168 wrote:
    Hi All,
    I am using Oracle 9i and I have an Oracle Type which has been created as follows
    create or replace TYPE "Dummy" AS VARRAY (500) OF VARCHAR2(50)
    It is assigned a set of values as follows:
    oracle.sql.ArrayDescriptor desc = oracle.sql.ArrayDescriptor.createDescriptor("Dummy", stmt.getConnection());
    oracle.sql.ARRAY newArray;
    newArray = new oracle.sql.ARRAY(desc, stmt.getConnection() , filter); //where filter contains the values here
    I am trying to execute the following statement but I get an error.
    SELECT process_instance_id, workstep_name, status FROM WORKSTEP
    WHERE PROCESS_INSTANCE_ID IN table(cast(newarray)))
    AND WORKSTEP_NAME = 'X';
    When I execute this I get a ORA-00936: missing expression
    Can you pls point out what's wrong here and how I can cast a varray as a table and use it in an "IN" clause?
    Thanks in advance.
    AD.I'm not sure why you're using a VARRAY, i would personally use a NESTED TABLE
    create or replace TYPE better_Dummy AS table OF VARCHAR2(50);
    /As i find them more flexible.
    Also, i would be quite sad to come into an environment and see that someone had created a database object using double quotes like you have to preserve case sensitivity (it's really a pain in the ***).
    That being said, here's the syntax you're looking for.
    create or replace TYPE Dummy AS VARRAY (500) OF VARCHAR2(50);
    ME_XE?declare
      2    in_dummy  dummy default dummy('a','b');
      3    x         number;
      4  begin
      5
      6    select count(*)
      7    into x
      8    from dual
      9    where 'a' in (select column_value from table(cast(in_dummy as dummy)));
    10
    11    dbms_output.put_line(x);
    12  end;
    13  /
    1
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.14
    ME_XE?

Maybe you are looking for

  • Table for Vendor balance as on a given date

    Hi, We have to send daily vendor balance to a different system through XI. At present we take the open items from BSIK and transfer all open items. But it has performance issues. i need a table from where by giving the Vendor number and company code

  • Photos on front blog page

    Hi. I know that in my blog, I have a choice in the inspector as to how many lines show up on the main blog page -- none or all of them. But what I can't figure out is it I can also show the photo(s) in the entry(ies) without making a person click on

  • Compaq Presario CQ60-112LA: Problems with the wireless

    Hello!!! :D:D:D:D I send my greetings to the community. I want to write 2 things before to tell you about my problem: 1. I'm sorry for my English, It isn't so good. 2. I'm Newbie in Arch Linux but not in GNU/Linux (I'm not an expert ) and I've read t

  • I lost my apps ability to work when I synced.  I'm really confused at Itunes and synching. How do I get my apps back?

    I tried to sync my ipad with my computer and it seemed to disable my ipad apps. Any help for how to restore them?

  • Illustrator CC tool pallets disappearing

    Anyone else having this problem? the essential took pallets will often just disappear. changing to another workspace brings up other pallets but then some of those don't work right. I've only had this problem once I installed Yosemite... Seems like a