SQL%BULK_ROWCOUNT collection type

Hello,
My goal is to create a procedure that takes as IN parameter SQL%BULK_ROWCOUNT and count number of rows that was inserted.
PROCEDURE count_rows(rows_in IN ???)
AS
     l_counter NUMBER := 0;
BEGIN
     FOR indx IN rows_in.FIRST..rows_in.LAST LOOP
          l_counter := l_counter + rows_in(indx)
     END LOOP;
     DBMS_OUTPUT.PUT_LINE(l_counter);
END;
Does anybody knows what to put in place of ???.
Thanks!

34MCA2K2 wrote:
It is after all an array of positive integer. You can create nested table as below & use it.
No, you can not. Two PL/SQL associative array types are not same types even thogh they have identical definitions:
SQL> declare
  2      type type1 is table of pls_integer index by pls_integer;
  3      type type2 is table of pls_integer index by pls_integer;
  4      v_type1 type1;
  5      v_type2 type2;
  6  begin
  7      v_type2 := v_type1;
  8  end;
  9  /
    v_type2 := v_type1;
ERROR at line 7:
ORA-06550: line 7, column 16:
PLS-00382: expression is of wrong type
ORA-06550: line 7, column 5:
PL/SQL: Statement ignored
SQL>
So without knowing SQL%BULK_ROWCOUNT type name we can't create procedure. And since Oracle is not telling us type name this can't be done. Well, technically it can, but it beats the purpose:
SQL> CREATE OR REPLACE
  2    PROCEDURE count_rows(rows_in IN sys.OdciNumberList)
  3      AS
  4       l_counter NUMBER := 0;
  5  BEGIN
  6       FOR indx IN rows_in.FIRST..rows_in.LAST LOOP
  7         l_counter := l_counter + rows_in(indx);
  8       END LOOP;
  9       DBMS_OUTPUT.PUT_LINE(l_counter);
10  END;
11  /
Procedure created.
SQL> DECLARE
  2    TYPE NumList IS TABLE OF NUMBER;
  3    depts NumList := NumList(30, 50, 60);
  4    v_counts sys.OdciNumberList := sys.OdciNumberList();
  5  BEGIN
  6    FORALL j IN depts.FIRST..depts.LAST
  7      DELETE FROM emp_temp WHERE department_id = depts(j);
  8    FOR i IN depts.FIRST..depts.LAST LOOP
  9      v_counts.extend;
10      v_counts(i) := SQL%BULK_ROWCOUNT(i);
11    END LOOP;
12    count_rows(v_counts);
13  END;
14  /
56
PL/SQL procedure successfully completed.
SQL>
SY.

Similar Messages

  • SQL*Modeler - creation of VARRAY or Collection Type of scalar type errors

    In SQl*Modeler 2.0.0 Build 584, I can create either VARRAY or Collections. These work fine for usre defined structured types but I encounter huge problems when I use a simple scalar type of number or varchar2.
    For instance I create a new collection type, give it a name, specify its a collection (or VARRAY, same problem) then click datatype. On the select Data type box I select logical type. A new window opens, I select VARCHAR from the drop down list.
    Enter the size 15, everything appears fine. I click OK, the select data type screen now shows a logical type of VARCHAR(15).
    So far I'm happy. I generate the DDL, everthing is fine, the DDL contains my collection of VARCHAR2(15).
    Now I save the model, close it and re-open the same model. My collection is now of VARCHAR so the next time I generate it will get an error because the syntax is wrong because it has no length. Same problem happens when selecting a NUMBER, looses the precision and scale but at least that command still works, just with a maximum numeric value.
    Ok, so lets try creating distinct types. Why we can't access domains when specifying types from here remains a mystery to me.
    So I create a distinct type Varchar2_15 which is of Logical type VARCHAR and give it a size. Similarly, create another distinct type of NUMERIC_22_0 precision 22 scale 0. This seems to get around the problem of losing the data but the DDL generated shows the datatype to be either VARCHAR (not VARCHAR2) and NUMERIC(22), not number(22). Now I know that VARCHAR currently maps to VARCHAR2 but isn't guaranteed to in the future (even though its been like that since V6) and NUMERIC is just an alias for NUMBER but its going to confuse a lot of java people and its totally inconsitent and just plain wrong.
    Any suggestions or workarounds will be gratefully received.
    Ian Bainbridge

    Hi Ian,
    I see a bug in save/load of collection types and as result no size or precision and scale information. It's fixed in new release.
    However I cannot reproduce the problem with distinct types - I have them generated as varchar2 and number (this is for Oracle).
    You can check:
    - database you use in DDL generation - I got varchar and numeric for MS SQL Server;
    - mapping of logical types VARCHAR and NUMERIC to native types in "Types Administration".
    Philip
    PS - I was able to reproduce it - I looked at wrong place - DDL generation for collection types is broken - it's ok for columns. I logged bug for that.
    Edited by: Philip Stoyanov on Jun 28, 2010 8:55 PM

  • PLS-00642: local collection types not allowed in SQL statements

    Hi,
    I want to retrieve empno in plsql table.
    Now based on the empno in plsql table I want to retrieve thier deptno in another plsql table/varray.
    SQL> declare
      2   type vdeptno  is table of number;
      3    v_deptno vdeptno;
      4    TYPE e_tab is table of  PLS_INTEGER INDEX BY PLS_INTEGER;
      5    empno_tab e_tab;
      6   Begin
      7  Select empno bulk collect into empno_tab FROM emp;
      8  FOR i in empno_tab.FIRST..empno_tab.LAST
      9  LOOP
    10   dbms_output.put_line(empno_tab(i));
    11   Select deptno into v_deptno
    12   FROM emp
    13    where empno=empno_tab(i);
    14   END loop;
    15  END;
    16  /
    Select deptno into v_deptno
    ERROR at line 11:
    ORA-06550: line 11, column 21:
    PLS-00642: local collection types not allowed in SQL statementsAny other way to do the same.
    Twinkle

    When you use this method ...
    type vdeptno is table of number;
    v_deptno vdeptno;
    You need to allocate space to the object prior to inserting into it , (use .EXTENDS for this). Or you need to initialize it while declaring it.
    or try the following
    SQL> declare
    2 type vdeptno is table of number;
    3 v_deptno vdeptno;
    4 TYPE e_tab is table of PLS_INTEGER INDEX BY PLS_INTEGER;
    5 empno_tab e_tab;
    6 Begin
    7 Select empno bulk collect into empno_tab FROM emp;
    8 FOR i in empno_tab.FIRST..empno_tab.LAST
    9 LOOP
    10 dbms_output.put_line(empno_tab(i));
    11 Select deptno bulk collect into v_deptno
    12 FROM emp
    13 where empno=empno_tab(i);
    14 END loop;
    15 END;
    16 /
    Edited by: user9276238 on Jun 14, 2010 3:26 AM

  • Error-local collection types not allowed in SQL statements

    TYPE WEEK_NUM_T  IS VARRAY(10) OF VARCHAR2(10);
    vc_weeknum WEEK_NUM_T;
    SELECT DISTINCT to_char(y.week_number_in_year) BULK COLLECT INTO vc_weeknum
        FROM DD_TMP x, TIME y
        WHERE x.DATE_TM = y.ORACLE_DATE;
    INSERT INTO TMP_HOLD
        (SELECT *
             FROM TMP
             WHERE DATE_TM IN (SELECT * FROM TABLE(vc_weeknum));It seems like the TABLE() function don't work. What is the workaround?

    You haven't provided enough of your code to tell, but you are probably trying to use a pl/sql type instead of a sql type. Please see the reproduction of error, then correction below.
    -- reprouction of error:
    scott@ORA92> CREATE TABLE tmp_hold AS SELECT * FROM dept WHERE 1 = 2
      2  /
    Table created.
    scott@ORA92> DECLARE
      2    TYPE WEEK_NUM_T     IS VARRAY(10) OF VARCHAR2(10);
      3    vc_weeknum WEEK_NUM_T;
      4  BEGIN
      5    SELECT DISTINCT deptno
      6    BULK   COLLECT INTO vc_weeknum
      7    FROM   emp;
      8 
      9    INSERT INTO TMP_HOLD
    10    SELECT *
    11    FROM   dept
    12    WHERE  deptno IN
    13             (SELECT * FROM TABLE(vc_weeknum));
    14  END;
    15  /
             (SELECT * FROM TABLE(vc_weeknum));
    ERROR at line 13:
    ORA-06550: line 13, column 31:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 13, column 25:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 9, column 3:
    PL/SQL: SQL Statement ignored
    -- correction:
    scott@ORA92> CREATE OR REPLACE TYPE WEEK_NUM_T AS TABLE OF VARCHAR2(10);
      2  /
    Type created.
    scott@ORA92> DECLARE
      2    vc_weeknum WEEK_NUM_T;
      3  BEGIN
      4    SELECT DISTINCT deptno
      5    BULK   COLLECT INTO vc_weeknum
      6    FROM   emp;
      7 
      8    INSERT INTO TMP_HOLD
      9    SELECT *
    10    FROM   dept
    11    WHERE  deptno IN
    12             (SELECT * FROM TABLE (CAST (vc_weeknum AS week_num_t)));
    13  END;
    14  /
    PL/SQL procedure successfully completed.
    scott@ORA92> SELECT * FROM tmp_hold
      2  /
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
    scott@ORA92>

  • Pl/sql table - row type records

    Hi,
    Is there any limit on the number of records that a pl/sql table (row type) can accomodate.Iam using oracle 10g

    user11200499 wrote:
    I have gone thru that url, nothing on the maximum number of records that can be present in pl/sql table is given there. Will be very helpful if you can let me know if there is any such limitation.There is no such thing as a PL/SQL "+table+". A table, in Oracle terminology, means colums and rows and indexes and the ability to scale data, effectively read and process and filter and aggregate data.
    A so-called PL/SQL "+table+" is nothing at all like this.
    The correct term for it, and used in all other programming languages, are arrays (procedural term) and collections (object orientated term).
    An array/collection is a local memory structure in the unit of code. In PL/SQL, that means PGA (process global area) memory. And as this uses server memory, you should not abuse it and only use as much that is truly needed.
    Make a PL/SQL array/collection too large, and PGA grows.. and can have a very negative impact on performance. It can even cause the server to crawl to halt, where you will struggle to enter a commandline command on the server as it is spending 99% of CPU time trying to deal with memory requests and page swapping.
    So what do we then use arrays/collections for in PL/SQL?
    For the very same reason we use in any other programming language - dealing with managing local programming data in a more effective memory structure. Such as bulk processing when requiring a buffer variable that can be passed to and from the PL and SQL engines.
    This does NOT mean using it as you would use it as if it is a SQL table. As it is not.
    So to answer your question of how large a PL/SQL array or collection can be? That depends entirely on the problem you are trying to solve. If it is for example bulk processing, then typically a collection of a 100 rows provides the best balance between the amount of (expensive) PGA memory being used versus the increase in performance by reducing context switching between the PL and SQL engines.
    If the rows are quite small, perhaps even a 1,000 row collection. More than that seldom decreases context switching enough to justify the increase in expensive PGA.
    So what should then be used to store larger data structures in PL/SQL? GTT or Global Temporary Tables. As this is a proper SQL table structure. Can be indexed. Natively supports SQL. Can scale with data volumes.
    And most importantly, it does not consume dedicated process memory and will not blow server memory.

  • How to use a collection type of bind variable for execute dynamic statement

    Hi,
    We have a case where we copy selective data from Schema A To Schema B in one oracle database. The copy is achieved by using
    execute immediate 'insert into '||target_schema||'.tablea select * from '||from_schema||'.table a where a.id in (select test_id from '||from_schema||'.table c);';
    This works fine it takes an average of 10 seconds to copy around 14 tables. We have a requirement to bring this time to 2 seconds. One observation has been the clause
    "select test_id from '||from_schema||'.table c" in the above sql statement repeats for many inserts . Thus we were thinking to bulk fetch this set of tests ids and use a bind vatiable of collection type for the execute immediate clause. Any suggestions on how to achieve it?
    Thanks,
    Chandana

    >
    One observation has been the clause
    "select test_id from '||from_schema||'.table c" in the above sql statement repeats for many inserts
    >
    So what? Constructing a string for a table level insert and parsing it can't possibly be a performance problem. If you were creating a string in a loop to insert rows into a table by getting the data FROM a collection - that's a problem that keeps showing up in the forums.
    I'm with bravid and Nikolay on this one. First find out which side, select/insert, the problem is on.
    As they said you need to provide more information about the process.
    And using collections for your use case is definitely not the thing to do.
    1. How many rows are we talking about?
    2. Are the rows being inserted into an empty table?
    3. Are you running these queries during peak production hours or in a batch windows?
    Tune the SELECT if the problem is on that side.
    Post an execution plan for the SELECT part of a query you think should run faster.
    SET SERVEROUTPUT ON
    SET AUTOTRACE TRACEONLY
    SQL> select * from emp;
    Execution Plan
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |    14 |   546 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| EMP  |    14 |   546 |     3   (0)| 00:00:01 |
    SQL>On the INSERT side you might be able to use bulk inserts
    ALTER TABLE myTable NOLOGGING;
    INSERT /*+ append */ INTO myTable . . .
    ALTER TABLE myTable LOGGINGIf the insert tables are always reused you could just leave them as NOLOGGING. Since you can't recover bulk data you need to make sure to get a good backup after the loads if you need to recover the data from the logs rather than just reload it yourself.

  • Query result window doesn't show contents of collection types

    Hello,
    I use SQL Developer version 3.1.07.
    When inspecting the result of a query in the query window, for collection types containing object types, the contents of the object types are not shown. So you can see the collection having a number of object types, but the content of each object type is not displayed.
    In version 3.1.05 this worked well, so for object type the content is displayed.
    Could you import this functionality again in 3.1.07?
    Best regards,
    Joop

    Hi Joop,
    Have you tried double clicking on the grid cell? That should open an editor to show the individual member object details. If double clicking does not work in some random area of the grid cell, try (scrolling if necessary first) clicking on the extreme right edge of the cell.
    There is some history behind this change. It started with a performance issue populating the grid for SDO_GEOMETRY objects:
    Re: SQLD 3.1EA -  Fails to render resultset output containing SDO_GEOMETRY
    The performance fix resulted in complaints in this forum against the SQL Developer 3.1 production release and logging another bug:
    SQL Developer 3.0.04 - SDO_GEOM Issues
    As far as I know, there has been no resolution on this issue, so the 3.1.07.42 behavior will probably remain unchanged in the next release. But as one of the posts indicates, you can have multiple SQL Developer versions installed on one machine -- you may want to keep that 3.1.05 early adopter version installed in order to view the object details within collections.
    Regards,
    Gary
    SQL Developer Team

  • Populate collection type from XMLType

    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE     11.1.0.7.0     Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    Please bear with me as I'm new to this XML DB thing and also this is my first post.
    I'm trying to populate collection type from XMLType. I was able to populate a table from XMLType but
    couldn't figure out a way to populate the collection type. Here is the description of my problem:
    Object Type:
    CREATE OR REPLACE TYPE DOC_ROWTYPE AS OBJECT
         REFERENCENUMBER VARCHAR2(255),
         REQID NUMBER(12),
         REQDETID NUMBER(12),
         FROMAMOUNT VARCHAR2(31),
         TOAMOUNT VARCHAR2(31),
         TOACCOUNTID NUMBER(12),
         TOACCOUNTNUMBER VARCHAR2(35),
         FROMACCOUNTID NUMBER(12),
         FROMACCOUNTNUMBER VARCHAR2(35),
    Collection Type:
    CREATE OR REPLACE TYPE DOC_TABLETYPE IS TABLE OF DOC_ROWTYPE;
    I have a physical table which is created when I registered a schema.
    A table (Temp_Result) got created with column SYS_NC_ROWINFO$ which is of XMLType.
    As you can see this is only a temporary table which will store the response XML which I want to finally get it to collection type.
    XML to parse:
    <code>
    <TFSResponse>
    <TFS>
    <refNumber>12345</refNumber>
    <reqId>123</reqId>
    <reqDetId>111</reqDetId>
    <fromAmount>20</fromAmount>
    <toAmount>20</toAmount>
    <fromAccount>
    <accountId>22222</id>
    <accountNumber>12345678</number>
    </fromAccount>
    <toAccount>
    <accountId>33333</id>
    <accountNumber>123456789</number>
    </toAccount>
    </TFS>
    .... many TFS Tags
    </TFSResponse>
    </code>
    So each object in the collection is one TFS tag.
    Any advice on how to implement this?

    Does this help
    SQL> CREATE OR REPLACE TYPE ACCOUNT_T as OBJECT (
      2    "accountId"       NUMBER(12),
      3    "accountNumber"   VARCHAR2(35)
      4  )
      5  /
    Type created.
    SQL> show errors
    No errors.
    SQL> --
    SQL> CREATE OR REPLACE TYPE TFS AS OBJECT(
      2     "refNumber"  VARCHAR2(255),
      3     "reqId"      NUMBER(12),
      4     "reqDetId"   NUMBER(12),
      5     "fromAmount" VARCHAR2(31),
      6     "toAmount"   VARCHAR2(31),
      7     "fromAccount" ACCOUNT_T,
      8     "toAccount"   ACCOUNT_T
      9  );
    10  /
    Type created.
    SQL> show errors
    No errors.
    SQL> --
    SQL> CREATE OR REPLACE TYPE TFS_C
      2      as TABLE of TFS
      3  /
    Type created.
    SQL> show errors
    No errors.
    SQL> --
    SQL> CREATE OR REPLACE Type TFS_RESPONSE_T as OBJECT(
      2    "TFSResponse" TFS_C
      3  );
      4  /
    Type created.
    SQL> show errors
    No errors.
    SQL> /
    Type created.
    SQL> CREATE OR REPLACE type CODE_T as OBJECT(
      2    "code" TFS_RESPONSE_T
      3  );
      4  /
    Type created.
    SQL> show errors
    No errors.
    SQL> --
    SQL>
    SQL> with "MY_XML" as
      2  (
      3    select XMLTYPE(
      4  '<code>
      5     <TFSResponse>
      6             <TFS>
      7                     <refNumber>12345</refNumber>
      8                     <reqId>123</reqId>
      9                     <reqDetId>111</reqDetId>
    10                     <fromAmount>20</fromAmount>
    11                     <toAmount>20</toAmount>
    12                     <fromAccount>
    13                             <accountId>22222</accountId>
    14                             <accountNumber>12345678</accountNumber>
    15                     </fromAccount>
    16                     <toAccount>
    17                             <accountId>33333</accountId>
    18                             <accountNumber>123456789</accountNumber>
    19                     </toAccount>
    20             </TFS>
    21             <TFS>
    22                     <refNumber>12346</refNumber>
    23                     <reqId>123</reqId>
    24                     <reqDetId>111</reqDetId>
    25                     <fromAmount>20</fromAmount>
    26                     <toAmount>20</toAmount>
    27                     <fromAccount>
    28                             <accountId>22222</accountId>
    29                             <accountNumber>12345678</accountNumber>
    30                     </fromAccount>
    31                     <toAccount>
    32                             <accountId>33333</accountId>
    33                             <accountNumber>123456789</accountNumber>
    34                     </toAccount>
    35             </TFS>
    36             <TFS>
    37                     <refNumber>12347</refNumber>
    38                     <reqId>123</reqId>
    39                     <reqDetId>111</reqDetId>
    40                     <fromAmount>20</fromAmount>
    41                     <toAmount>20</toAmount>
    42                     <fromAccount>
    43                             <accountId>22222</accountId>
    44                             <accountNumber>12345678</accountNumber>
    45                     </fromAccount>
    46                     <toAccount>
    47                             <accountId>33333</accountId>
    48                             <accountNumber>123456789</accountNumber>
    49                     </toAccount>
    50             </TFS>
    51     </TFSResponse>
    52  </code>') as "XML"
    53    from DUAL
    54  )
    55  select
    56    "TMOBILE"."CODE_T"(
    57      "TMOBILE"."TFS_RESPONSE_T"(
    58        CAST(
    59          MULTISET(
    60            select
    61              "TMOBILE"."TFS"(
    62                "refNumber_000002",
    63                "reqId_000003",
    64                 "reqDetId_000004",
    65                "fromAmount_000005",
    66                "toAmount_000006",
    67                "TMOBILE"."ACCOUNT_T"(
    68                  "accountId_000007",
    69                  "accountNumber_000008"
    70                ),
    71                 "TMOBILE"."ACCOUNT_T"(
    72                  "accountId_000009",
    73                  "accountNumber_000010"
    74                )
    75              )
    76              FROM
    77                XMLTABLE(
    78                  '/TFS'
    79                  passing "TFSResponse_000001"
    80                   COLUMNS
    81                   "refNumber_000002"                  VARCHAR2(255)                       PATH 'refNumber',
    82                   "reqId_000003"                      NUMBER                              PATH 'reqId',
    83                    "reqDetId_000004"                   NUMBER                              PATH 'reqDetId',
    84                   "fromAmount_000005"                 VARCHAR2(31)                        PATH 'fromAmount',
    85                    "toAmount_000006"                   VARCHAR2(31)                        PATH 'toAmount',
    86                     "accountId_000007"                  NUMBER                              PATH 'fromAccount/accountId',
    87                      "accountNumber_000008"              VARCHAR2(35)                        PATH 'fromAccount/accountNumber',
    88                     "accountId_000009"                  NUMBER                              PATH 'toAccount/accountId',
    89                      "accountNumber_000010"              VARCHAR2(35)                        PATH 'toAccount/accountNumber'
    90                )
    91          ) as "TMOBILE"."TFS_C"
    92        )
    93      )
    94    )
    95    FROM MY_XML,
    96      XMLTABLE(
    97        '/'
    98        passing "XML"
    99        COLUMNS
    100              "TFSResponse_000001"                XMLTYPE                             PATH 'code/TFSResponse/TFS'
    101       )
    102
    SQL> /
    CODE_T(TFS_RESPONSE_T(TFS_C(TFS('12345', 123, 111, '20', '20', ACCOUNT_T(22222, '12345678'), ACCOUNT_T(33333, '123456789')), TFS('12346', 123, 111, '20', '20',
    ACCOUNT_T(22222, '12345678'), ACCOUNT_T(33333, '123456789')), TFS('12347', 123, 111, '20', '20',
    ACCOUNT_T(22222, '12345678'), ACCOUNT_T(33333, '123456789')))))
    SQL>

  • (8I) COLLECTION TYPE 변경 방법

    제품 : SQL*PLUS
    작성날짜 : 1999-05-12
    COLLECTION TYPE 변경 방법
    =========================
    collection type은 attribute나 column의 데이타 타입으로
    사용된다. 이전에 정의한 collection type의 property를 변경해야
    하는 경우가 종종 발생하게 되는데 그 작업이 간단하지 않다.
    ALTER TYPE문은 spec이나 body를 재컴파일하거나, member를 추가
    하는 경우에는 사용할 수 있지만 현재 collection의 property를
    바꿀수는 없다. 만약 변경하려한다면 다음 에러가 날 것이다.
    ORA-22319: type attribute information altered in ALTER TYPE
    collection의 property 를 변경하기 위해서는 collection을 drop
    한 후, 다시 만들어야 하는데 참조하는 오브젝트가 존재하는 경우
    dependency 문제로 인해 collection type을 drop 할 수도 없다.
    ORA-02303: cannot drop or replace a type with type
    or table dependents
    즉, Oracle 8i 이전에는 collection의 attribute를 변경하려면
    parent table과 collection type을 모두 drop한 후, 재생성
    해야만 했다.
    그러나 Oracle 8i new feature인 ALTER TABLE DROP COLUM문을
    이용하여 parent table을 drop하지 않고도 collection type의
    attribute를 변경할 수 있게 되었다.
    다음은 parent table을 drop하지 않고 collection (nested table)을
    변경하는 예제이다.
    SQL> /* object type 선언 */
    SQL> create type object_type as object (
    col1 number,
    col2 varchar2(20));
    SQL> /* nested table type 선언*/
    SQL> create type object_ntable as table of object_type;
    SQL> /* parent table 생성 */
    SQL> create table master (
    col1 number primary key,
    col2_list object_ntable)
    nested table col2_list store as master_col2;
    SQL> insert into master values (1,
    object_ntable(object_type(1,'1'),
    object_type(1,'2'),
    object_type(1,'3')));
    SQL> insert into master values (2,
    object_ntable(object_type(2,'1'),
    object_type(2,'2'),
    object_type(2,'3')));
    SQL> commit;
    1. 기존에 저장된 collection data를 임시 table에 저장.
    SQL> create table temp_detail as
    select m.col1 "MASTER_COL1", n.col1, n.col2
    from master m, table(m.col2_list) n;
    SQL> select * from temp_detail;
    MASTER_COL1 COL1 COL2
    1 1 1
    1 1 2
    1 1 3
    2 2 1
    2 2 2
    2 2 3
    2. parent table의 nested table column을 drop 하기
    3. nested table type을 drop하기.
    4. object type을 drop하기.
    SQL> alter table master drop column col2_list;
    SQL> drop type object_ntable;
    SQL> drop type object_type;
    5. attribute을 변경한 object type을 재생성하기
    6. nested table type을 재생성하기.
    SQL> create type object_type as object (
    col1 number,
    col2 varchar2(30));
    SQL> create type object_ntable as table of object_type;
    7. parent table에 nested table column을 추가하기.
    SQL> alter table master add (col2_list object_ntable)
    nested table col2_list store as master_col2;
    8. 임시 테이블에 저장했던 data를 nested table에 저장하기.
    SQL> update master m
    set col2_list = (cast(multiset(
    select col1, col2
    from temp_detail
    where master_col1 = m.col1)
    as object_ntable))
    where col1 in
    (select distinct master_col1 from temp_detail);
    SQL> select * from master;
    COL1
    COL2_LIST(COL1, COL2)
    1
    OBJECT_NTABLE(OBJECT_TYPE(1, '1'), OBJECT_TYPE(1, '2'), OBJECT_TYPE(1, '3'))
    2
    OBJECT_NTABLE(OBJECT_TYPE(2, '1'), OBJECT_TYPE(2, '2'), OBJECT_TYPE(2, '3'))
    * TABLE(), DROP COLUMN 절은 Oracle 8i new features 이다.

    each member of the insert must be a collection, hope this eample helps;
    CREATE OR REPLACE PROCEDURE fast_way IS
    TYPE parent_rec IS RECORD (
    part_num dbms_sql.number_table,
    part_name dbms_sql.varchar2_table);
    p_rec parent_rec;
    CURSOR c IS
    SELECT part_num, part_name
    FROM parent;
    l_done BOOLEAN;
    BEGIN
    OPEN c;
    LOOP
    FETCH c BULK COLLECT INTO p_rec.part_num, p_rec.part_name
    LIMIT 500;
    l_done := c%notfound;
    FORALL i IN 1 .. p_rec.part_num.COUNT
    INSERT INTO child
    (part_num, part_name)
    VALUES
    (p_rec.part_num(i), p_rec.part_name(i));
    EXIT WHEN (l_done);
    END LOOP;
    COMMIT;
    CLOSE c;
    END fast_way;
    /

  • Topic: Incorrect Tag:Multiple Attributes with Same Collection Type

    I have an Object Type that contains multiple attributes with the same collection type. When I use OracleXML getXML to generate xml, the tag for all elements created for any of the matching types is the tag for the 1st of the similar attributes.
    work_t_v is an object view of a relational schema
    SQL> desc work_t_v
    Name Null? Type
    WORK_ID NUMBER(38)
    TITLE_OF_WORK VARCHAR2(512)
    MESH_HEADINGS MESH_HEADINGS_T
    AUTHORS AUTHORS_T
    COMMENT_ON WORK_REFERENCES_T
    COMMENT_IN WORK_REFERENCES_T
    ERRATUM_IN WORK_REFERENCES_T
    REPUBLISHED_FROM WORK_REFERENCES_T
    REPUBLISHED_IN WORK_REFERENCES_T
    SQL> desc work_references_t
    work_references_t TABLE OF WORK_REFERENCE_T
    Name Null? Type
    REFSOURCE VARCHAR2(255)
    NOTE VARCHAR2(255)select
    work.work_id,
    work.title_of_work,
    work.comment_on comment_on,
    work.comment_in comment_in,
    work.erratum_in erratum_in,
    work.republished_from republished_from,
    work.republished_in republished_in
    from work_t_v work
    where work_id = 99350984
    results in tag of <comment_on> for all the elements built from the work_references_t type (i.e., there are no <comment_in>, <erratum_in>, <republished_from> or <republished_in> elements)
    sample result is:
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [CommentOn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [CommentIn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [ErratumIn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [RepublishedFrom]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [RepublishedIn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    The above xml should be:
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [CommentOn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_IN>
    <COMMENT_IN_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [CommentIn]</REFSOURCE>
    </COMMENT_IN_ITEM>
    </ERRATUM_IN>
    <COMMENT_ON>
    <ERRATUM_IN_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [ErratumIn]</REFSOURCE>
    </ERRATUM_IN_ITEM>
    </ERRATUM_IN>
    <REPUBLISHED_FROM>
    <REPUBLISHED_FROM_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [RepublishedFrom]</REFSOURCE>
    </REPUBLISHED_FROM_ITEM>
    </REPUBLISHED_FROM>
    <REPUBLISHED_IN>
    <REPUBLISHED_IN_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601 [RepublishedIn]</REFSOURCE>
    </REPUBLISHED_IN_ITEM>
    </REPUBLISHED_IN>bracketed portion [] is contained within the refsource string to indicate what type of reference it should be displayed as.
    I also found that if I use the -withDTD parameter to include the dtd, the dtd includes the appropriate elements (comment_in, erratum_in, republished_from and republished_in). However, it incorrectly defines refsource and note multiple times (once for each WORK_REFERENCES_T attribute).
    Are these known problems? Will they be fixed? I'm more concerned about the XML problem than the DTD problem.
    Thanks! -- John Butler
    null

    Using the version of XML SQL Utility that comes with the next XSQL Servlet release 0.9.8.6 I did the following:
    create type foo as object (a number);
    create type foolist as table of foo;
    create view fooview
    as select
    cast(multiset(
    select sal from emp where rownum < 2)
    as foolist) list1,
    cast(multiset(
    select sal from emp where rownum < 2)
    as foolist) list2
    from dual;
    When I request a "SELECT * FROM FOOVIEW"
    through getXML I get:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW num="1">
    <LIST1>
    <LIST1_ITEM>
    <A>800</A>
    </LIST1_ITEM>
    </LIST1>
    <LIST2>
    <LIST2_ITEM>
    <A>800</A>
    </LIST2_ITEM>
    </LIST2>
    </ROW>
    </ROWSET>
    So this appears fixed in the next code drop.
    In the interim, I'll email you the new JAR file until (since it won't be on OTN for a few more days).
    null

  • Incorrect Tag:Multiple Attributes with Same Collection Type

    I have an Object Type that contains multiple attributes with the
    same collection type. When I use OracleXML getXML to generate
    xml, the tag for all elements created for any of the matching
    types is the tag for the 1st of the similar attributes.
    work_t_v is an object view of a relational schema
    SQL> desc work_t_v
    Name Null? Type
    WORK_ID NUMBER(38)
    TITLE_OF_WORK VARCHAR2(512)
    MESH_HEADINGS MESH_HEADINGS_T
    AUTHORS AUTHORS_T
    COMMENT_ON WORK_REFERENCES_T
    COMMENT_IN WORK_REFERENCES_T
    ERRATUM_IN WORK_REFERENCES_T
    REPUBLISHED_FROM WORK_REFERENCES_T
    REPUBLISHED_IN WORK_REFERENCES_T
    SQL> desc work_references_t
    work_references_t TABLE OF WORK_REFERENCE_T
    Name Null? Type
    REFSOURCE VARCHAR2(255)
    NOTE VARCHAR2(255)
    select
    work.work_id,
    work.title_of_work,
    work.comment_on comment_on,
    work.comment_in comment_in,
    work.erratum_in erratum_in,
    work.republished_from republished_from,
    work.republished_in republished_in
    from work_t_v work
    where work_id = 99350984
    results in tag of <comment_on> for all the elements built from
    the work_references_t type (i.e., there are no <comment_in>,
    <erratum_in>, <republished_from> or <republished_in> elements)
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601
    [CommentOn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601
    [CommentIn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601
    [ErratumIn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601
    [RepublishedFrom]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    <COMMENT_ON>
    <COMMENT_ON_ITEM>
    <REFSOURCE>J Infect Dis 1998 Aug;178(2):601
    [RepublishedIn]</REFSOURCE>
    </COMMENT_ON_ITEM>
    </COMMENT_ON>
    bracketed portion [] is contained within the refsource string to
    indicate what type of reference it should be displayed as.
    I also found that if I use the -withDTD parameter to include the
    dtd, the dtd includes the appropriate elements (comment_in,
    erratum_in, republished_from and republished_in). However, it
    incorrectly defines refsource and note multiple times (once for
    each WORK_REFERENCES_T attribute).
    Are these known problems? Will they be fixed? I'm more
    concerned about the XML problem than the DTD problem.
    Thanks! -- John Butler
    null

    Using the version of XML SQL Utility that comes with the next XSQL Servlet release 0.9.8.6 I did the following:
    create type foo as object (a number);
    create type foolist as table of foo;
    create view fooview
    as select
    cast(multiset(
    select sal from emp where rownum < 2)
    as foolist) list1,
    cast(multiset(
    select sal from emp where rownum < 2)
    as foolist) list2
    from dual;
    When I request a "SELECT * FROM FOOVIEW"
    through getXML I get:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW num="1">
    <LIST1>
    <LIST1_ITEM>
    <A>800</A>
    </LIST1_ITEM>
    </LIST1>
    <LIST2>
    <LIST2_ITEM>
    <A>800</A>
    </LIST2_ITEM>
    </LIST2>
    </ROW>
    </ROWSET>
    So this appears fixed in the next code drop.
    In the interim, I'll email you the new JAR file until (since it won't be on OTN for a few more days).
    null

  • Collection type supported in Oracle Forms Forms [32 Bit] Version 6.0.8.11.3

    Hi
    I am trying to call this from forms.
    I am getting error no data found whenever this calles IF condition but from backend if run it from a script it works fine.
    So I was thinking whether Forms PL/SQL version supports collection types.
    I am using Forms [32 Bit] Version 6.0.8.11.3 (Production) for Oracle Application 11.5.10 version.
    IF (p_emp_ids.COUNT > 0) THEN
    FOR r IN v_emp_ids.FIRST..v_pkg_ids.LAST LOOP
    Thanks in Advance

    Is it just a a typo that the IF is on P_emp_ids and the loop is on V_em_ids?
    However: the NO_DATA_FOUND exception suggests that you may be falling down a crack in your collection. If you have a missing element between FIRST and LAST you will get a no_data_found. Suppose these elements are there:
    (1), (2). (3), (5), (6)
    You will start at FIRST (1) and finish at LAST (6). But your loop on R will try to find the element at (4). Which isn't there. Oops...
    To prove that's what's happening, you can wrap the inside of the loop with an exception handler
       BEGIN
          do the access to v_emp_ids(r)
       EXCEPTION
          WHEN NO_DATA_FOUND then (log a message with the value if R in it)
       END;If you want to walk a collection with gaps (a "sparse" collection), this is the way:
      DECLARE
         r pls_integer;
      BEGIN
         r := v_empids.FIRST
         LOOP
             EXIT when r IS NULL;
             do the business on v_empids(r);
             r := v_empids(r).NEXT;
         END LOOP;Now, why didn't this work in Forms, but did on the server? Possible reasons:
    - your back end script was set up differently - so you had a dense collection (no gaps)
    - Client side PL/SQL is different from server side (is it still version 1.x?)
    HTH
    Regards Nigel
    Message was edited by:
    nthomas

  • Using TABLE() syntax with collection types

    Hi,
    I have created a function that returns a collection type as TABLE of VARCHAR2.
    Function works just fine like this:
    SELECT * FROM TABLE(some_fcn('VALUE1','VALUE2'));
    Where I am passing in static values.
    However, I need to join this with another table, passing in the values from that table as the parameters:
    SELECT f.some_table_key, t.* FROM some_table f, TABLE(some_fcn(f.col1,f.col2)) t;
    When I do this, I get the error "ORA-00904: "F"."COL1": invalid identifier"
    I am using 11gR1
    Could anyone please offer some guidance with this?
    Thanks!
    Edited by: odinsride on Aug 23, 2010 3:30 PM
    Edited by: odinsride on Aug 23, 2010 3:39 PM

    What are you doing differently?
    SQL> create or replace function some_fcn (col1 varchar2, col2 int)
       return sys.odcivarchar2list
    as
    begin
       return sys.odcivarchar2list (col2);
    end some_fcn;
    Function created.
    SQL> select ename, t.* from emp f, table(some_fcn(f.ename, f.empno)) t
    ENAME      COLUMN_VAL
    SMITH      7369     
    ALLEN      7499     
    WARD       7521     
    JONES      7566     
    MARTIN     7654     
    BLAKE      7698     
    CLARK      7782     
    SCOTT      7788     
    KING       7839     
    TURNER     7844     
    ADAMS      7876     
    JAMES      7900     
    FORD       7902     
    MILLER     7934     
    14 rows selected.can you give a description of your table some_table?

  • Collection type support in Forms version 6.0.8.11.3

    Hi
    I am trying to call this from forms.
    I am getting error no data found whenever this calls IF condition but from backend if run it from a script it works fine.
    So I was thinking whether Forms PL/SQL version supports collection types.
    I am using Forms [32 Bit] Version 6.0.8.11.3 (Production).
    IF (p_emp_ids.COUNT > 0) THEN
    FOR r IN v_emp_ids.FIRST..v_pkg_ids.LAST LOOP
    Thanks in Advance

    Is it just a a typo that the IF is on P_emp_ids and the loop is on V_em_ids?
    However: the NO_DATA_FOUND exception suggests that you may be falling down a crack in your collection. If you have a missing element between FIRST and LAST you will get a no_data_found. Suppose these elements are there:
    (1), (2). (3), (5), (6)
    You will start at FIRST (1) and finish at LAST (6). But your loop on R will try to find the element at (4). Which isn't there. Oops...
    To prove that's what's happening, you can wrap the inside of the loop with an exception handler
       BEGIN
          do the access to v_emp_ids(r)
       EXCEPTION
          WHEN NO_DATA_FOUND then (log a message with the value if R in it)
       END;If you want to walk a collection with gaps (a "sparse" collection), this is the way:
      DECLARE
         r pls_integer;
      BEGIN
         r := v_empids.FIRST
         LOOP
             EXIT when r IS NULL;
             do the business on v_empids(r);
             r := v_empids(r).NEXT;
         END LOOP;Now, why didn't this work in Forms, but did on the server? Possible reasons:
    - your back end script was set up differently - so you had a dense collection (no gaps)
    - Client side PL/SQL is different from server side (is it still version 1.x?)
    HTH
    Regards Nigel
    Message was edited by:
    nthomas

  • How to fetch rows from PL/SQL table(Collections)

    Hi,
    I retrived rows from the table and stored in to table type.
    Now I want fetch these rows and display on the screen. Pls guide me.
    following code is my code:
    DECLARE
    type t1 is table of emp%rowtype index by binary_integer;
    var1 t1;
    v_counter number:=0;
    BEGIN
    select * bulk collect into var1 from emp;
    for vr in var1.first..var1.last
    loop
    dbms_output.put_line(var1(1)); --Got an Error Here. Acually I don't Know how to  fetch.
    update dept set deptno=var1.deptno --Here also Error occured.
    end loop;
    END;

    Fetching rows to display them is a task for the client tool. You need to define a ref cursor therefore.
    If you just want to play around, here we go
    SQL> DECLARE
      2    type t1 is table of emp%rowtype index by binary_integer;
      3    var1 t1;
      4    v_counter number:=0;
      5  BEGIN
      6    select * bulk collect into var1 from emp;
      7    for vr in 1..var1.count loop
      8      dbms_output.put_line(var1(vr).ename);
      9      update dept set deptno=var1.deptno Here also Error occured.
    10    end loop;
    11  END;
    12  /
    SCOTT
    ADAMS
    PL/SQL procedure successfully completed.
    SQL>

Maybe you are looking for

  • Performance issues with Oracle EE 9.2.0.4 and RedHat 2.1

    Hello, I am having some serious performance issues with Oracle Enterprise Edition 9.2.0.4 and RedHat Linux 2.1. The processor goes berserk at 100% for long (some 5 min.) periods of time, and all the ram memory gets used. Some environment characterist

  • My iMac has slowed to a crawl

    My iMac is running extremely slow (10-15 minutes to open up small simple applications). I ran Disk Utility and when I repaired permissions, I noticed a warning ( Warning: SUID file "System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/M

  • OWA Exchange 2013 SP1 Security Update KB3011140 December 2014

    After performing this update on our server, I noticed now users can no longer recover items from deleted items in OWA. The page always errors out now. The KB installed was KB3011140 something went wrong Sorry, we can't get that information right now.

  • Is it possible to call XSLT from Java Mapping Class?

    Hi, does someone have experience with this? Or any ideas? And, if yes, how can be this XSLT called? Is it necessary to specify special path? Or it is the XSLT file placed in the same directory? Thanx in advance, Peter Message was edited by: Peter Jar

  • Itunes on my pc stops working when I connect my iphone

    itunes on my pc stops working when i connect up my iphone i do not sync my iphone with the pc (i only do this to charge the phone) syncing is done with the library at home on the mac any ideas on how to fix? talked to tech support and they could not