Collection in PL/SQL

Hi...All,
I write procedure by declaring cursor then using for...loop to insert data into table now i decide to change program by using collection data type and use command BULK COLLECT INTO....
But the cursor is come from joining three tables like this:
v_rec t4%rowtype;
cursor c1 is select ..... from t1,t2,t3 where .... ;
for i in c1 loop
statements,
v_rec.col1 := c1.col1;
statements,
insert into t4 values (...)
end loop;
commit;
How to declare the Table data type variable
TYPE NameTab IS TABLE OF .... ?
Thank you,
Mcka

> fetch beta bulk collect into b;
Obviously an example - but note that the LIMIT clause should always be used when putting a bulk fetch like this into production code.
So just to add to dnikiforov posting... :
If you do not manage the size of the array, you run the risk of seriously increase the PGA size of the Oracle process and causing a huge performance impact on the server due to extensive memory swapping.
The basic template is:
loop
fetch <cursor> into <buffer> limit <number>;
for i in 1..<buffer>.Count
loop
<process buffer(i) >
end;
exit when <cursor>%NOTFOUND;
end loop;
Note the exit test is at the end of the loop - not just after the FETCH command with a single row fetch. Reason: the LIMIT could be a 100 and only 10 rows are fetched. %NOTFOUND is true. However you first want to process those 10 rows before exiting the loop - thus this exit loop condition is moved to after the processing of the fetch buffer array.

Similar Messages

  • Working with Collection in PL/SQL

    Hi,
    I am new in PL/SQL programming.
    I am writing a PL/SQL stored procedure that have a "data collection" output argument. It extracts a list of data items (eg. id, temperature) from a table. The data items are stored in a collection (as the number of items is unknown therefore I am going to use nested table instead of varray). Some of the fields in the data items on the data collection will be transformed (eg. convert temperature from Fahrenheit to Celsius) before it is returned to the caller program.
    * Question1:
    How can I add data into a nested table (or varray) one at a time? (see sample codes below)
    Eg.
    I declared a nested table in the spec:
    type test_record_t is record (
    test_id number,
    test_value number);
    type test_list_t is table of test_record_t;
    test record test_record_t;
    test_list test_list_t;
    Then in the body:
    i := 1;
    loop
    fetch test_cursor into test_record;
    exit when test_cursor%notfound;
    test_list(i) := test_record; -- syntax error
    i := i+1;
    end loop;
    All the examples I have seen so far that the list is populated when it is initialised:
    Eg.
    test_list := test_list_t(test_record1, test_record2);
    but not
    test_list(1) := test_record1;
    test_list(2) := test_record2;
    It could be that I am trying to implement the PL/SQL codes with my C/C++ thinking instead of PL/SQL. Do you have any suggestion?
    * Question2:
    How do you declare a PL/SQL procedure that have a nested table (or varray) output argument?
    Eg.
    PROCEDURE test_proc(data_list OUT ???);
    Thank you very much and best regards,
    Phil
    PS. I am using Oracle 9.2

    Phil, why are you using a collection to pass the data? PL/SQL collections reside in expensive PGA memory. Collections are thus not very scalable. The bigger they are, the less server memory for everyone else on the server. The more processes/sessions using your code, the more collections there are.. and again less server memory to go around for everyone else.
    The primary reason for using collections in PL/SQL is to create a buffer that allows you to pass more rows between the PL and SQL engines in a single call. This reduces context switching and increases performance. PL in 10G already does this implicitly for you as bulk fetching/passing data is so critical to performance. PL/SQL collections allow you to explicitly manage this yourself.
    Using a PL/SQL collection to "buffer" data for a client application is usually not the best of ideas. It involves using expensive PGA memory. It involves copying data from the inexpensive and scalable buffer cache into PL. It requires PL to crunch that data.
    Typically doing all this in SQL is significantly faster and many times more scalable. E.g. using PL to construct the SQL statement that does this data crunching and processing, have PL create a cursor in the SQL engine for that statement, and then pass a reference handle to the client for using that cursor - fetching the data directly from the buffer cache and SQL engine.
    Remember that despite the PL being very similar to other procedural languages, the environment it runs in is very different environment. Inside a database server process. With tight integration with the SQL engine.
    PL is both a client language (it uses SQL as the server supplying data) and a server language (it is called by clients as a service on the server).
    In order to use PL effectively, the very basic design rule is minimise PL/SQL and maximise SQL. Do not do in PL what SQL is perfectly capable of doing.. as the SQL engine will do it better and faster and more scalable than your PL code can ever do it.

  • How to send nested object collection to PL/SQL Procedure as an Input param

    How to send nested object collection to PL/SQL Procedure as an Input parameter.
    The scenario is there is a parent mapping object containing a collection(java.sql.Array) of child objects.
    I need to send the parent object collection to PL/SQL procedure as a input parameter.
    public class parent{
    String attr1;
    String attr2;
    Child[] attr3;
    public class Child{
    String attr1;
    SubChild[] attr2;
    public class SubChild{
    String attr1;
    Urgent!!!
    Edited by: javiost on Apr 30, 2008 2:09 AM

    javiost wrote:
    How to send nested object collection to PL/SQL Procedure as an Input parameter.There are a few ways to do this, all of which likely depend on the particular database you're using.
    Urgent!!!Not to me...

  • Table function on a collection in Dynamic SQL

    Hello,
    I am trying to create a refcursor by selecting from a collection using table function.
    If I use the Select statement the query executes, but if I put the Select statement in a string
    the collection variable does not get resolved. The resaon I am putiing it in a string is because the
    WHERE clause will be passed a parameter. The code below is an anonymous block but will be changed to a
    procedure once I get it to work.
    I have tried many different ways but was unsuccessful.
    Please see if anybody cann assist or what I am trying to achive is not possible, so provide an alternative.
    The error I am getting is
    ORA-00904: "V_ALARM_REC_TABLE": invalid identifier
    ORA-06512: at line 50
    Thanks.
    Bimal
    DECLARE
    TYPE c_refcurtype IS REF CURSOR;
    x c_refcurtype;
    p_recordset c_refcurtype;
    v_rec mc2_dev2.mc2_alarm_rec_type := mc2_dev2.mc2_alarm_rec_type(null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null);
    v_alarm_rec_table mc2_dev2.mc2_alarm_rec_table := mc2_dev2.mc2_alarm_rec_table();
    v_select varchar2(200) := 'select a.* from ';
    v_table varchar2(200) := 'table(v_alarm_rec_table) a ';
    v_where varchar2(200) := 'where a.alarm_rule_def_uid = 9';
    v_query varchar2(32000);
    BEGIN
    MC2_ALARM.create_mc2_alarm(x, 1); --- ( X is a refcursor, which I will use to populate v_alarm_rec_table a (nested table collection)
    LOOP
    FETCH x INTO v_rec.record_cnt,
    v_rec.rn,
    v_rec.alarm_precision_order,
    v_rec.alarm_rule_def_uid,
    v_rec.alarm_type_def_uid,
    v_rec.alarm_rule_scope_uid,
    v_rec.trigger_tpl_master_uid,
    v_rec.alarm_scope_def_uid,
    v_rec.alarm_object_uid,
    v_rec.error_type,
    v_rec.all_error_codes,
    v_rec.enabled,
    v_rec.start_hour,
    v_rec.end_hour,
    v_rec.day_type,
    v_rec.alarm_severity_def_uid,
    v_rec.on_watch_duration,
    v_rec.update_on_status_change,
    v_rec.log_ind,
    v_rec.email_to,
    v_rec.email_from,
    v_rec.send_email,
    v_rec.stale_period;
    EXIT WHEN x%NOTFOUND;
    v_alarm_rec_table.extend;
    v_alarm_rec_table(v_alarm_rec_table.last) := v_rec;
    END LOOP;
    CLOSE x;
    v_query := v_select||v_table||v_where; -- ERROR OCCURS AT THIS LINE as it cannot resolve the TABLE name  v_alarm_rec_table)
    dbms_output.put_line('sql: '||v_query);
    OPEN p_recordset FOR v_query;
    LOOP
    FETCH p_recordset INTO v_rec.record_cnt,
    v_rec.rn,
    v_rec.alarm_precision_order,
    v_rec.alarm_rule_def_uid,
    v_rec.alarm_type_def_uid,
    v_rec.alarm_rule_scope_uid,
    v_rec.trigger_tpl_master_uid,
    v_rec.alarm_scope_def_uid,
    v_rec.alarm_object_uid,
    v_rec.error_type,
    v_rec.all_error_codes,
    v_rec.enabled,
    v_rec.start_hour,
    v_rec.end_hour,
    v_rec.day_type,
    v_rec.alarm_severity_def_uid,
    v_rec.on_watch_duration,
    v_rec.update_on_status_change,
    v_rec.log_ind,
    v_rec.email_to,
    v_rec.email_from,
    v_rec.send_email,
    v_rec.stale_period;
    EXIT WHEN p_recordset%NOTFOUND;
    some dbms_output statements...
    END LOOP;
    END;
    The error I am getting is
    ORA-00904: "V_ALARM_REC_TABLE": invalid identifier
    ORA-06512: at line 50

    Thanks Timur/Solomon,
    mc2_dev2 is the schema name.
    mc2_alarm_rec_table is a SQL type.
    Here are the scripts:
    CREATE OR REPLACE TYPE MC2_DEV2.mc2_alarm_rec_type IS OBJECT
    ( record_cnt NUMBER,
    rn number,
    alarm_precision_order NUMBER(6),
    alarm_rule_def_uid NUMBER(6),
    alarm_type_def_uid NUMBER(6),
    alarm_rule_scope_uid NUMBER(6),
    trigger_tpl_master_uid NUMBER(6),
    alarm_scope_def_uid NUMBER(6),
    alarm_object_uid NUMBER(6),
    error_type VARCHAR2(1),
    all_error_codes VARCHAR2(1),
    enabled VARCHAR2(1),
    start_hour NUMBER(2),
    end_hour NUMBER(2),
    day_type NUMBER(2),
    alarm_severity_def_uid NUMBER(6),
    on_watch_duration NUMBER(6),
    update_on_status_change VARCHAR2(1),
    log_ind VARCHAR2(1),
    email_to VARCHAR2(128),
    email_from VARCHAR2(128),
    send_email VARCHAR2(1),
    stale_period          NUMBER(6)
    CREATE OR REPLACE TYPE MC2_DEV2.MC2_ALARM_REC_TABLE IS TABLE OF MC2_DEV2.mc2_alarm_rec_type;
    If I popoulate the cursor with the following code:
    OPEN p_recordset FOR
    select a.* from table (v_alarm_rec_table) a where a.alarm_rule_def_uid = 9;
    there is no issue it works just fine.
    But when when I use
    OPEN p_recordset FOR v_query; ---- where v_query := v_select||v_table||v_where;
    the variable v_alarm_rec_table does not get resolved.
    Regards,
    Bimal

  • Could not initialize a collection+[Microsoft][ODBC SQL Server Driver]Invali

    Hi All,
    I am getting the following message, when i try to retreive the child object from the parent..
    Session sess = sessionFactory.openSession();
    Team obj = (Team) sess.load(Team.class, new Long(2457600));
    Set s = obj.getPlayers();
    System.out.println("PLayer -- "+obj.getPlayers());
    Error Message :
    org.hibernate.exception.GenericJDBCException: could not initialize a collection: [com.test.Team.players#2457600]
    org.hibernate.exception.GenericJDBCException: could not initialize a collection: [com.test.Team.players#2457600]
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.loadCollection(Loader.java:1351)
    at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:106)
    at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:484)
    at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
    at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1346)
    at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:170)
    at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:47)
    at org.hibernate.collection.PersistentSet.toString(PersistentSet.java:221)
    at java.lang.String.valueOf(String.java:2131)
    at java.lang.StringBuffer.append(StringBuffer.java:370)
    at com.test.TeamPlayer.main(TeamPlayer.java:70)
    Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
    at sun.jdbc.odbc.JdbcOdbc.SQLGetDataDouble(JdbcOdbc.java:3658)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getDataDouble(JdbcOdbcResultSet.java:5579)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getLong(JdbcOdbcResultSet.java:635)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getLong(JdbcOdbcResultSet.java:653)
    at org.hibernate.type.LongType.get(LongType.java:26)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
    at org.hibernate.persister.collection.AbstractCollectionPersister.readKey(AbstractCollectionPersister.java:612)
    at org.hibernate.loader.Loader.readCollectionElement(Loader.java:545)
    at org.hibernate.loader.Loader.readCollectionElements(Loader.java:344)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:299)
    at org.hibernate.loader.Loader.doQuery(Loader.java:384)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
    at org.hibernate.loader.Loader.loadCollection(Loader.java:1344)
    ... 10 more
    Team [Parent] <--> Player [Child]
    Team.hbm.xml
    <hibernate-mapping>
    <class name="com.test.Team" table="dbo.teams">
    <id name="id" column="team_id" >
    <generator class="hilo"/>
    </id>
    <property name="name" column="team_name" />
    <property name="city" column="city" />
    <set name="players" cascade="all" inverse="true" lazy="true">
    <key column="team_id"/>
    <one-to-many class="com.test.Player"/>
    </set>
    </class>
    </hibernate-mapping>
    PLayer.hbm.xml:
    <hibernate-mapping>
    <class name="com.test.Player" table="dbo.players">
    <id name="id" column="player_id">
    <generator class="hilo"/>
    </id>
    <property name="firstName" column="first_name" />
    <property name="lastName" column="last_name" />
    <property name="draftDate" column="draft_date" />
    <property name="annualSalary" column="salary" />
    <property name="jerseyNumber" column="jersey_number" />
    <many-to-one name="team" class="com.test.Team" column="team_id" />
    </class>
    </hibernate-mapping>
    Any help would be highly appreciated..
    Thanks,
    /Shridhar..

    http://forums.hibernate.org/viewtopic.php?t=928277&view=next&sid=e3ed34f2b57526386ba6ac7ac29b6471

  • Bulk collect in pl/sql table SOLVED

    Hi All,
    TYPE r_nparameter IS RECORD( col1 tab.col1%TYPE, col2 tab.col2%TYPE);
    TYPE t_no_seq IS TABLE OF r_nparameter INDEX BY BINARY_INTEGER;
    the t_no_seq is not initialized.
    My Question is
    If we use t_itn_seq, in a BULK COLLECT operation in a select statement as...
    SELECT col1, col2 BULK COLLECT INTO t_no_seq
    and there is no record found for this query and exception is taken care of....thereafter we use this table in for loop as..
    FOR icount IN 1..t_no_seq.COUNT
    will this count raise any exception?
    Best Regards.
    Message was edited by:
    user560602

    It's not difficult to test this yourself...
    SQL> declare
      2    type t_x is table of number index by binary_integer;
      3    v_x t_x;
      4  begin
      5    select rownum
      6    bulk collect into v_x
      7    from dual
      8    connect by rownum <= 10;
      9    for i in 1..v_x.count
    10    loop
    11      dbms_output.put_line(to_char(v_x(i)));
    12    end loop;
    13  end;
    14  /
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    PL/SQL procedure successfully completed.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    type t_x is table of number index by binary_integer;
      3    v_x t_x;
      4  begin
      5    select rownum
      6    bulk collect into v_x
      7    from dual
      8    where 1=0;
      9    for i in 1..v_x.count
    10    loop
    11      dbms_output.put_line(to_char(v_x(i)));
    12    end loop;
    13* end;
    SQL> /
    PL/SQL procedure successfully completed.

  • Using Collection in a sql statement.

    Hi I want to perform the following statement:
    DELETE FROM ALLOCATION_ELEC_MATRIX
    WHERE dgo_ean_id in (lt_inter_dgos);
    The collection lt_inter_dgos holds my dgo_ean_id's(varchars).
    I can't find a way to get it to work.
    The collection is declared as follows:
    TYPE Interface_param_dgos IS TABLE OF VARCHAR2(20);
    lt_inter_dgos Interface_param_dgos := Interface_param_dgos();
    then later on the collection gets filled. But how can i get it to work to use it in my sql statement?
    I don't won't to use a for loop around it since it would give me problems if I use more collections with a different amount of values in it.

    The standard approach is to use SQL collection type and table function,
    for example
    SQL> create TYPE Interface_param_dgos IS TABLE OF VARCHAR2(20);
      2  /
    Type created.
    SQL> create or replace package my_pkg
      2  is
      3   lt_inter_dgos Interface_param_dgos := Interface_param_dgos();
      4   function get_coll return Interface_param_dgos;
      5  end;
      6  /
    Package created.
    SQL> create or replace package body my_pkg
      2  is
      3   function get_coll return Interface_param_dgos
      4   is
      5   begin
      6    return lt_inter_dgos;
      7   end;
      8  end;
      9  /
    Package body created.
    SQL> begin
      2   my_pkg.lt_inter_dgos.extend(3);
      3   my_pkg.lt_inter_dgos(1) := 'SMITH';
      4   my_pkg.lt_inter_dgos(2) := 'KING';
      5   my_pkg.lt_inter_dgos(3) := 'ALLEN';
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> select ename from emp;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> delete from emp where ename in (select column_value from table(my_pkg.get_coll));
    3 rows deleted.
    SQL> select ename from emp;
    ENAME
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    11 rows selected.Rgds.

  • Bulk collect in pl/sql

    Hi there, need help, is it a right way of using bulk collect here?  As I could not get the correct result. 
    The problem is the 'where clause' is only taking 'SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE' column name
    to output but not for the rest of columns. The output given is only 3 records from  'SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE'. 
    In fact, other column names have records existed.  Please advise.  Regards, BE.
    FOR i in 1..l_flex_column_list.count LOOP
         dbms_output.put_line('SEAEGO_CC_FAMILYMODEL_INFO_'||l_flex_column_list(i).column_name);
            BEGIN                   
            SELECT evsvv.value_set_name, evsvv.internal_name, evsvv.display_name
                BULK COLLECT INTO l_flex_value_list  -- table collection
               FROM ego_value_set_values_v evsvv
                *WHERE evsvv.value_set_name= 'SEAEGO_CC_FAMILYMODEL_INFO_'||l_flex_column_list(i).column_name;*
         EXCEPTION
           WHEN NO_DATA_FOUND THEN
              l_flex_value_list:=NULL;
           WHEN OTHERS THEN
              dbms_output.put_line('test ');
         END;
         END LOOP;
          dbms_output.put_line('');
          BEGIN
            FOR i in 1..l_flex_value_list.count LOOP
            dbms_output.put_line(l_flex_value_list(i).value_set_name ||' '||
                           l_flex_value_list(i).internal_name||' '||
                           l_flex_value_list(i).display_name);
            END LOOP;
          END;
    END;
    *Output*
    SEAEGO_CC_FAMILYMODEL_INFO_PRODUCT_TYPE
    SEAEGO_CC_FAMILYMODEL_INFO_INTERNAL_PRODUCT_NAME
    SEAEGO_CC_FAMILYMODEL_INFO_NUMBER_OF_HEADS
    SEAEGO_CC_FAMILYMODEL_INFO_NUMBER_OF_DISCS
    SEAEGO_CC_FAMILYMODEL_INFO_GENERATION
    SEAEGO_CC_FAMILYMODEL_INFO_DESIGN_APPLICATION
    SEAEGO_CC_FAMILYMODEL_INFO_FORM_FACTOR
    SEAEGO_CC_FAMILYMODEL_INFO_INTERFACE
    SEAEGO_CC_FAMILYMODEL_INFO_BASE_WARRANTY_MONTHS
    SEAEGO_CC_FAMILYMODEL_INFO_PHYSICAL_SECTOR_SIZE
    SEAEGO_CC_FAMILYMODEL_INFO_MODEL_HEIGHT
    SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE
    _incorrect result_
    SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE NO ENCRYPTION No Encryption
    SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE FDE BASE FDE Base
    SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE FDE FIPS 140-2 FDE FIPS 140-2
    Query Statement for other columns
    SELECT evsvv.value_set_name, evsvv.internal_name, evsvv.display_name
                FROM ego_value_set_values_v evsvv
            WHERE evsvv.value_set_name  = 'SEAEGO_CC_FAMILYMODEL_INFO_MODEL_HEIGHT'
    *Output*
    SEAEGO_CC_FAMILYMODEL_INFO_MODEL_HEIGHT     5MM     0.196 IN/5MM
    SEAEGO_CC_FAMILYMODEL_INFO_MODEL_HEIGHT     7MM     0.276 IN/7MM
    SEAEGO_CC_FAMILYMODEL_INFO_MODEL_HEIGHT     8MM     0.315 IN/8MM
    SEAEGO_CC_FAMILYMODEL_INFO_MODEL_HEIGHT     9.5MM     0.374 IN/9.5MM
    SEAEGO_CC_FAMILYMODEL_INFO_MODEL_HEIGHT     10.5MM     0.431 IN/10.5MM

    Hi there, the select statement below actually query record into 'l_flex_value_list' record variable by
    looping in different values e.g. SEAEGO_CC_FAMILYMODEL_INFO_BASE_WARRANTY_MONTHS,
    SEAEGO_CC_FAMILYMODEL_INFO_PHYSICAL_SECTOR_SIZE and SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE.
    But, my problem is the 'l_flex_value_list' is only storing the result for SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE, overwriting
    the values of SEAEGO_CC_FAMILYMODEL_INFO_BASE_WARRANTY_MONTHS and SEAEGO_CC_FAMILYMODEL_INFO_PHYSICAL_SECTOR_SIZE.
    What is the logic should be in this case?
       FOR i in 1..l_flex_column_list.count LOOP
      --   dbms_output.put_line('SEAEGO_CC_FAMILYMODEL_INFO_'||l_flex_column_list(i).column_name);
        dbms_output.put_line(l_flex_column_list(i).column_name||' '||
                          l_flex_column_list(i).column_value);
            BEGIN                   
            SELECT evsvv.value_set_name, evsvv.internal_name, evsvv.display_name
            BULK COLLECT INTO l_flex_value_list
            FROM ego_value_set_values_v evsvv
            WHERE evsvv.value_set_name= 'SEAEGO_CC_FAMILYMODEL_INFO_'||l_flex_column_list(i).column_name;
          --  AND internal_name = l_flex_column_list(i).column_value;
         EXCEPTION
           WHEN NO_DATA_FOUND THEN
              l_flex_value_list:=NULL;
           WHEN OTHERS THEN
              dbms_output.put_line(' ');
         END;
         END LOOP;
    ------------------the PL/SQL -----------------------
    Declare
    l_query  VARCHAR2(2000);
    l_where VARCHAR2(2000);
    l_bind_var1      VARCHAR2(40);
    l_bind_var2      VARCHAR2(40);
    l_sql            NUMBER:=0;
    l_column_name    VARCHAR2(100);
    l_column_value   VARCHAR2(200);
    p_item_id NUMBER :=NULL;--931104 ;
    p_item_number       VARCHAR2(40):='9NH2D4-570';
    p_stmodel  VARCHAR2(40):='ST901603FGD1E1-RK';
    TYPE l_flex_column_rec IS RECORD
        column_name   varchar2(100),
        column_value  varchar2(100));
    TYPE l_flex_column_tab IS TABLE OF l_flex_column_rec;
    l_flex_column_list l_flex_column_tab;
    TYPE l_flex_value_rec IS RECORD
    ( value_set_name   fnd_flex_value_sets.flex_value_set_name%type,
       internal_name    fnd_flex_values.flex_value%type,
       display_name     fnd_flex_values_tl.description%type);
    TYPE l_flex_value_tab IS TABLE OF l_flex_value_rec;
    l_flex_value_list l_flex_value_tab;
    BEGIN
       IF p_stmodel is not null THEN
          IF p_item_number IS NULL AND p_item_id IS NULL THEN
           l_where  :='and st.stmodelnumber= :1 and sp.detailedproductname=''GENERIC''';
           l_bind_var1 := p_stmodel;
           l_sql := 1;
          ELSIF p_item_number IS NULL AND p_item_id IS NOT NULL THEN
           l_where  :='and st.stmodelnumber=:1 and sc.ccitemnumber = (select msi.segment1                       
                       from mtl_system_items msi                       
                       where msi.inventory_item_id = :2 and rownum=1)';
           l_bind_var1 := p_stmodel;
           l_bind_var2 := p_item_id;
           l_sql :=2;
          ELSE
           l_where  :='and st.stmodelnumber=:1 and sc.ccitemnumber = (select msi.segment1                      
                       from mtl_system_items msi                      
                       where msi.segment1=:2 and rownum=1)';
           l_bind_var1 := p_stmodel;
           l_bind_var2 := p_item_number;
           l_sql :=2;
          END IF; 
       ELSE
         IF p_item_id is null and p_item_number is not null THEN
                l_where := 'and sc.ccitemnumber = (select msi.segment1                      
                           from mtl_system_items msi                      
                           where msi.segment1=:1 and rownum=1)';
                l_bind_var1 :=  p_item_number;
                l_sql := 1;
            ELSIF p_item_id is NOT null and p_item_number is null THEN
                l_where := 'and sc.ccitemnumber = ( select msi.segment1                       
                            from mtl_system_items msi                       
                            where msi.inventory_item_id = :1 and rownum=1)';
                 l_bind_var1 := p_item_id;
                 l_sql := 1;
            ELSIF p_item_id is not null and p_item_number is not null THEN
                l_where :='and sc.ccitemnumber = (select msi.segment1                      
                           from mtl_system_items msi                      
                           where msi.inventory_item_id =:1                      
                           AND msi.segment1=:2 and rownum=1)';
                l_bind_var1 := p_item_id;
                l_bind_var2 := p_item_number;
                l_sql :=2;
            END IF;
        END IF;
    l_query :='select decode(rn,1,''PRODUCT_TYPE'',2,''INTERNAL_PRODUCT_NAME'',3,''NUMBER_OF_HEADS'',4,''NUMBER_OF_DISCS'',5,''GENERATION'',6,''DESIGN_APPLICATION'',
            7,''FORM_FACTOR'',8,''INTERFACE'',9,''BASE_WARRANTY_MONTHS'',10,''PHYSICAL_SECTOR_SIZE'',11,''MODEL_HEIGHT'',''ENCRYPTION_TYPE'') as column_name,
            decode(rn,1,st.producttype,2,sp.internalproductname,3,sp.numberofheads,4,sp.numberofdiscs,5,sp.generation,6,sp.designapplication,7,st.formfactor,
            8,st.interface,9,st.warrantymonths,10,st.physical_sector_size,11,st.modelheight,st.encryption_type) as column_value
            FROM  seaeng_productmodel sp , seaeng_stmodel st, seaeng_ccitemnumber sc , (select rownum rn from dual connect by rownum <=12)
            WHERE sc.productmodelnumber = sp.productmodelnumber
            AND sp.stmodelnumber = st.stmodelnumber ';
      IF l_sql = 1 THEN
          EXECUTE IMMEDIATE  l_query ||l_where
                             BULK COLLECT INTO l_flex_column_list
                             USING l_bind_var1 ;
                     --        dbms_output.put_line(l_query||l_where);
        ELSIF
             l_sql =2 THEN
            EXECUTE IMMEDIATE l_query || l_where
                             BULK COLLECT INTO l_flex_column_list
                             using l_bind_var1,l_bind_var2;
                  dbms_output.put_line(l_query||l_where);
        END IF;
       FOR i in 1..l_flex_column_list.count LOOP
      --   dbms_output.put_line('SEAEGO_CC_FAMILYMODEL_INFO_'||l_flex_column_list(i).column_name);
        dbms_output.put_line(l_flex_column_list(i).column_name||' '||
                          l_flex_column_list(i).column_value);
            BEGIN                   
            SELECT evsvv.value_set_name, evsvv.internal_name, evsvv.display_name
            BULK COLLECT INTO l_flex_value_list
            FROM ego_value_set_values_v evsvv
            WHERE evsvv.value_set_name= 'SEAEGO_CC_FAMILYMODEL_INFO_'||l_flex_column_list(i).column_name;
          --  AND internal_name = l_flex_column_list(i).column_value;
         EXCEPTION
           WHEN NO_DATA_FOUND THEN
              l_flex_value_list:=NULL;
           WHEN OTHERS THEN
              dbms_output.put_line(' ');
         END;
         END LOOP;
          dbms_output.put_line('');
          BEGIN
            FOR i in 1..l_flex_value_list.count LOOP
            dbms_output.put_line(l_flex_value_list(i).value_set_name ||' '||
                           l_flex_value_list(i).internal_name||' '||
                           l_flex_value_list(i).display_name);
            END LOOP;
          END;
    END;
    -------OUTPUT
    SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE NO ENCRYPTION No Encryption
    SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE FDE BASE FDE Base
    SEAEGO_CC_FAMILYMODEL_INFO_ENCRYPTION_TYPE FDE FIPS 140-2 FDE FIPS 140-2

  • Metric collection Error MS SQL 2005 Backup

    Hi ,
    become on all "german !!! ' ms sql 2005 Server a collection error for the backup. I have install the newest ms sql plug-in .I have Grid Control 10.2.0.5
    the german error Message is :
    WARN collector: <nmecmc.c> Error exit. Error message: Error Querying:Bei der Konvertierung eines char-Datentyps in einen datetime-Datentyp liegt der datetime-Wert außerhalb des gültigen Bereichs.
    com.microsoft.sqlserver.jdbc.SQLServerException: Bei der Konvertierung eines char-Datentyps in einen datetime-Datentyp liegt der datetime-Wert außerhalb des gültigen Bereichs.
         at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(Unknown Source)
         at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
         at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(Unknown Source)
         at oracle.sysman.mpi.jdbc.microsoft_sqlserver_database.SQLServerJDBCQuery.executeQuery(SQLServerJDBCQuery.java:263)
         at oracle.sysman.mpi.jdbc.microsoft_sqlserver_database.SQLServerJDBCQuery.main(SQLServerJDBCQuery.java:1152)
    this mean that he have problems to convert char to datetime . But why ?
    On my English Server i habe no Problems with this collection.
    And NO , i can't only install English MS SQL Server . This is a Company Policy .
    Where the error of the collection ?
    Thx

    and one more:
    Cant find the key : SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Replication\\IsInstalled D:\OracleHomes\agent10g/sysman/admin/scripts/emx/microsoft_sqlserver_database\execmethod_32bit is_remote_login=0 namespace=root\default class=StdRegProv "sSubKeyName=SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Replication" sValueName=IsInstalled method=GetDWORDValue noprint=0 em_result=0 SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Replication IsInstalled

  • Can you generate a Schem Collection from an SQL Query

    Is there an Option that allows you to generate and XML Schema Collection in a Select Statement that will be loaded either to a table or an application.
    An example
    SELECT Column1, Column2, Column3
    FROM table
    FOR XML PATH('');
    An easy way to generate a template or a start without having to type from scratch?
    Antonio

    Hi Antonio,
    The FOR XML clause
    can generate the XML schema, you can reference the optional XMLSCHEMA.
    XMLSCHEMA [ ('TargetNameSpaceURI') ] 
    Returns inline XSD schema. You can optionally specify a target namespace URI when you specify this directive, which returns the specified namespace in the schema. For more information, see
    Generate an Inline XSD Schema.
    If you have any question, feel free to let me know.
    Best regards,
    Eric Zhang
    TechNet Community Support

  • XML Schema Collection (SQL Server 2012): Complex Schema Collection with Attribute - Should xs or xsd be used in the coding?

    Hi all,
    I just got a copy of the book "Pro SQL Server 2008 XML" written by Michael Coles (published by Apress) and try to learn the XML Schema Collection in my SQL Server 2012 Management Studio (SSMS2012). I studied Chapter 4 XML Collection of the book
    and executed the following code of Listing 4-8 Complex Schema with Attribute:
    -- Pro SQL Server 2008 XML by Michael Coles (Apress)
    -- Listing04-08.sql Complex XML Schema with Attribute
    -- shcColes04-08.sql saved in C:\\Documents\XML_SQL_Server2008_code_Coles_Apress
    -- 6 April 2015 8:00 PM
    CREATE XML SCHEMA COLLECTION dbo.ComplexTestSchemaCollection_attribute
    AS
    N'<?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="item">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="name" />
    <xs:element name="color" />
    <xs:group ref="id-price" />
    <xs:group ref="size-group" />
    </xs:sequence>
    <xs:attribute name="id" />
    <xs:attribute name="number" />
    </xs:complexType>
    </xs:element>
    <xs:group name="id-price">
    <xs:choice>
    <xs:element name="list-price" />
    <xs:element name="standard-cost" />
    </xs:choice>
    </xs:group>
    <xs:group name="size-group">
    <xs:sequence>
    <xs:element name="size" />
    <xs:element name="unit-of-measure" />
    </xs:sequence>
    </xs:group>
    </xs:schema>';
    GO
    DECLARE @x XML (dbo.ComplexTestSchemaCollection_attribute);
    SET @x = N'<?xml version="1.0"?>
    <item id="749" number="BK-R93R-62">
    <name>Road-150 Red, 62</name>
    <color>Red</color>
    <list-price>3578.27</list-price>
    <size>62</size>
    <unit-of-measure>CM</unit-of-measure>
    </item>';
    SELECT @x;
    GO
    DROP XML SCHEMA COLLECTION dbo.ComplexTestSchemaCollection_attribute;
    It worked nicely. But, I just found out the coding that was downloaded from the website of Apress and I just executed was different from the coding of Listing 4-8 listed in the book: all the <xs: ....> and </xs: ..> in my SSMS2012 are
    listed as <xsd:...> and </xsd:...> respectively in the book!!??  The same thing happens in the Listing 4-3 Simple XML Schema, Listing 4-5 XML Schema and Valid XML Document with Comple Type Definition, Listion 4-6 XML Schema and XML
    Document Document with Complex Type Using <sequence> and <choice>, and Listing 4-7 Complex XML Schema and XML Document with Model Group Definition (I executed last week) too.  I wonder: should xs or xsd be used in the XML
    Schema Collection of SSMS2012?  Please kindly help,  clarify this matter and explain the diffirence of using xs and xsd for me.
    Thanks in advance,
    Scott Chang   

    Hi Scott,
    Using xs or xsd depends on how you declare the namespace prefix.
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="item">
    I've posted a very good link in your last question, just in case you might have missed it, please see the below link.
    Understanding XML Namespaces
    In an XML document we use a namespace prefix to qualify the local names of both elements and attributes . A prefix is really just an abbreviation for the namespace identifier (URI), which is typically quite long. The prefix is first mapped to a namespace
    identifier through a namespace declaration. The syntax for a namespace declaration is:
    xmlns:<prefix>='<namespace identifier>'
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • 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

  • Problem with SQL query pulling info out of a collection

    Here's my issue, I use a PL/SQL query to pull info from an XML file and put it in a collection. I then query the collection with a SQL statement to pull the info from the collection and put it into a table. I can see that the collection is being created properly, but then my SQL query is failing to pull the info out of the collection. Here's my PL/SQL query:
    declare
    l_clob clob;
    l_buffer varchar2(32767);
    l_url varchar2(4000);
    l_http_req utl_http.req;
    l_http_resp utl_http.resp;
    begin
    utl_http.set_proxy(apex_application.g_proxy_server, NULL);
    l_url := 'http://www.jobster.com/partnerfeeds/Servinity/Servinity.xml';
    l_http_req := utl_http.begin_request(l_url);
    l_http_resp := utl_http.get_response(l_http_req);
    dbms_lob.createtemporary( l_clob, FALSE );
    dbms_lob.open( l_clob, dbms_lob.lob_readwrite );
    begin
    loop
    utl_http.read_text(l_http_resp, l_buffer);
    dbms_lob.writeappend( l_clob, length(l_buffer), l_buffer );
    end loop;
    exception
    when others then
    if sqlcode <> -29266 then
    raise;
    end if;
    end;
    utl_http.end_response(l_http_resp);
    apex_collection.create_or_truncate_collection('JOB_RESPONSE');
    apex_collection.add_member(
    p_collection_name => 'JOB_RESPONSE',
    p_clob001 => l_clob );
    end;
    This part works fine because I can check the collection and see the info was put there properly. Here's the XML file (part of it at least):
    <?xml version="1.0" encoding="UTF-8" ?>
    <job-list xmlns="http://jobster.com/feed/1.3">
    <site>
    <name>Jobster</name>
    <url>http://www.jobster.com</url>
    </site>
    <job>
    <id>58117925</id>
    <key>51253677</key>
    <featurelevel>1</featurelevel>
    <title>
    And here's the SQL query which isn't pulling anything back:
    select extractValue(value(t),'/*/name') "Name",
    extractValue(value(t),'/*/url') "URL"
    from apex_collections c,
    table(xmlsequence(extract(xmltype.createxml(c.clob001),'/job-list/site'))) t
    where c.collection_name = 'JOB_RESPONSE'
    What am I missing? Thanks in advance!

    my mistake<br>
    take a look to the examples can be very<br> helpful...sometimes<br>
    <br>
    select anz,rueck<br>
    <br>
    from (select (case when exists(select ek_id<br>
    from bh_einkuenfte<br>
    where ek_vgid=:P51_VG_ID<br>
    and ek_artid = a.ea_id)<br>
    then 'anything'<br>
    else a.ea_bez end) anz,<br>
    a.ea_seite rueck <br>
    from bh_einkunftsarten a<br>
    where a.ea_nummer <= 70<br>
    order by a.ea_nummer)<br>

  • Using sql functions (min, max, avg) on varray or table collection

    Hi,
    I would like to know if there is a way to use sql function or oracle sql function like Min,Max, Avg or percentile_cont on varray or table collection ?
    Does anyone encountered this type of problem ?
    Thanks

    Yes you can apply Min,Max, Avg... if varray or table collection type is SQL (created in the databaase) UDF, not PL/SQL declared type:
    SQL> set serveroutput on
    SQL> declare
      2      type str_tbl_type is table of varchar2(4000);
      3      str_tbl str_tbl_type := str_tbl_type('X','A','D','ZZZ');
      4      max_val varchar2(4000);
      5  begin
      6      select max(column_value)
      7        into max_val
      8        from table(str_tbl);
      9      dbms_output.put_line('Max value is "' || max_val || '"');
    10  end;
    11  /
          from table(str_tbl);
    ERROR at line 8:
    ORA-06550: line 8, column 18:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 8, column 12:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 5:
    PL/SQL: SQL Statement ignored
    SQL> create or replace type str_tbl_type is table of varchar2(4000);
      2  /
    Type created.
    SQL> declare
      2      str_tbl str_tbl_type := str_tbl_type('X','A','D','ZZZ');
      3      max_val varchar2(4000);
      4  begin
      5      select max(column_value)
      6        into max_val
      7        from table(str_tbl);
      8      dbms_output.put_line('Max value is "' || max_val || '"');
      9  end;
    10  /
    Max value is "ZZZ"
    PL/SQL procedure successfully completed.
    SQL> SY.

  • How to pass empty PL/SQL collection?

    I can pass an array as PL/SQL associative array into PL/SQL procedure/block.
    It works perfectly.
    But i can't pass empty array (e.g. new decimal[] {} ) as value - exception raised:
    System.InvalidOperationException:
    "OracleParameter.Value is invalid"
    I can receive empty collection FROM pl/sql, but can i pass empty collection TO pl/sql?

    Unfortunately, there are no any suitable workaround for this problem in thread mentioned above.
    Workaround given by Greg in the thread:
    You can get around it in the meantime by using
    Param1.Value = new string[1]{null};
    Param1.Size=0;Why is that not suitable?
    - Mark

Maybe you are looking for

  • Error message trying to burn keynote presentation in idvd

    I know this has been posted before - but I can't seem to find an answer to fix my problem. I am trying to export a 30 slide presentation from Keynote 3 to iDVD 6 - the presentation is using slides which should be the optimum slide size for iDVD (acco

  • Nokia 5800 -like compass navigation view (or app) ...

    Can I get anywhere same like navigation compass app to my new Nokia 701 (or any other Symbian ¨3 version) as Nokia 5800 had? When hunting, I like to add navigation points (for example where I left my car). Of course I can get walking navigation via m

  • How to set TextFormat to an InputTextfield in AS3.0?

    Hi all, I am trying to set the new TextFormat Object to an dynamically created Input TextField, using setTextFormat() methoad. But its not working.My code is here, can any one tell me the mistake which I made in this. var tft:TextFormat=new TextForma

  • Question after going to TrustedOnly signatures

    First thanks to all developers and contributors for the new pacman 4 release and the implementation of package signing. I tested pacman 4 for weeks before its official release and I used: SigLevel = Optional TrustAll Now I went to: SigLevel = Optiona

  • Should I delete the motion 4 library before installing motion 5?

    I just got a new Mac Pro with Yosemite on it, and I just installed FCP 7 last night, and when I tried to launch Motion, I discovered that Motion 4 won't run on Yosemite.  I'm a little puzzled about why the installer still let me install it -- I thoug