insertion in a nested table of pl/sql

worm 10.2.0.3

I know that I can do this in the example with a big collect but in the 'real' code, I have to be inserted...

My question is how to insert in a nested table of pl/sql?
create or replace type all_obj_obj as object(owner varchar2(30),object_name varchar2(30),object_type varchar2(30))
/

create or replace type all_obj_list as table of all_obj_obj
/

declare
 coll  all_obj_list := all_obj_list();
begin
 insert into table(coll) select owner,object_name,object_type from all_objects;
end;
/ 
I know that could do a select master, object_name, object_type bulk collect in coll but I do an insert for some reason as long as I can go in... anyway to do it?

Your "nested table" is not a "nested table" but a collection, a varable.
Obviously so can not INSERT in a memory structure.
Your need is not supposed, as BULK COLLECT would do the tric.
As you cannot disclose why you ' need; for this (you do not have) and also do not mention a version, as you ' assume; PL/SQL does not ever change or everyone uses the same version, no additional help is possible.

-----
Sybrand Bakker
Senior Oracle DBA

Tags: Database

Similar Questions

  • What is the preferred means of data transmission as a type of record between the nested table of pl/sql program or an associative array

    What is the preferred means of data transmission in the associative array of the nested table record vs

    Choose between Nested Tables and associative arrays

    The two nested tables and associative arrays (formerly index - by tables) use similar index notation, but they have different characteristics when it comes to persistence and ease of passing parameters.

    Nested tables can be stored in a column of data, but can of associative arrays. Nested tables can simplify the SQL operations where you would normally join a single-column table with a larger table.

    Associative arrays are appropriate for relatively small lookup tables where the collection can be constructed in memory whenever a procedure is called or a package is initialized. They are good for the collection of the information volume is unknown beforehand, because there is no fixed limit on their size. Their index values are more flexible, as associative array indices can be negative, can be no sequential and can use values of string instead of numbers.

    PL/SQL automatically converts between the bays of the host and the associative arrays that use values of digital keys. The most effective way to move the collections to and from the database server is to implement data values in associative arrays, and then use these associative arrays with erections in bulk (the FORALL statement or BULK COLLECT clause).

    With the help of documents and Collections of PL/SQL

    Read this:

    How to pass the record set as a parameter of the procedure.

    https://community.Oracle.com/thread/2375173?TSTART=0

  • How to insert rows in multiple tables in a sql

    I want to know how to insert multiple lines in a single sql statement.

    Let's insert records into the table emp and dept in a sql statement.


    Thank you

    It's here

    SQL>l
      1  insert all
      2    into emp values(8888,'WADE','MANAGER',7839,'01-MAR-2008',5000,100,20)
      3    into dept values(50,'MARKETING','NEW YORK')
      4* select * from dual
    SQL> /
    
    2 rows created.
    

    SS

  • ORA-22907: invalid CAST to a type that is not a nested table or VARRAY. Typed collection function

    Hello

    I tried to create a function that might return the type that is created on the outside.

    So I wrote script below. until the function created it compiled successfully, but after that, when the data querying, we encountered error,

    "ORA-22907: invalid CAST to a type that is not a nested table or VARRAY.

    SQL> create table emp
      2  (
      3    ename        varchar2(200 byte),
      4    mgr          number,
      5    employee_id  number
      6  );
    
    
    Table created.
    
    
    SQL> insert into emp (ename, mgr, employee_id)
      2       values ('king', 12, 1);
    
    
    1 row created.
    
    
    SQL> insert into emp (ename, mgr, employee_id)
      2       values ('clark', 12, 2);
    
    
    1 row created.
    
    
    SQL> commit;
    
    
    Commit complete.
    
    
    SQL> create or replace type t_emp as object (ename varchar2 (200), mgr number, employee_id number);
      2  /
    
    
    Type created.
    
    
    SQL> create or replace function f_emp return  t_emp
      2   is
      3  type rc_emp is ref cursor;
      4  r_emp rc_emp;
      5  v_emp t_emp;
      6  begin
      7   open r_emp for select * from emp where rownum=1;
      8   fetch r_emp into v_emp;
      9  close r_emp;
     10  return v_emp;
     11  exception
     12      when others then
     13      dbms_output.put_line(dbms_utility.format_error_stack);
     14      dbms_output.put_line(dbms_utility.format_call_stack);
     15      dbms_output.put_line(dbms_utility.format_error_backtrace);
     16      raise_application_error(-20001,sqlerrm);
     17  end;
     18  /
    
    
    Function created.
    
    
    SQL> show errors;
    No errors.
    SQL> select * from f_emp;
    select * from f_emp
                  *
    ERROR at line 1:
    ORA-04044: procedure, function, package, or type is not allowed here
    
    
    
    
    SQL> select * from table(cast (f_emp as t_emp));
    select * from table(cast (f_emp as t_emp))
                              *
    ERROR at line 1:
    ORA-22907: invalid CAST to a type that is not a nested table or VARRAY
    
    
    
    
    SQL>
    

    Like this:

    ...

    CREATE or REPLACE TYPE t_emp_array IS TABLE OF THE t_emp;

    /

    FUNCTION to CREATE or REPLACE f_emp RETURN t_emp_array

    is

    type rc_emp is ref cursor;

    r_emp rc_emp;

    v_emp_array t_emp_array: = t_emp_array();

    BEGIN

    R_emp OPEN for SELECT t_emp(ename,mgr,employee_id) FROM emp WHERE ROWNUM = 1;

    collect the fetch r_emp in bulk in v_emp_array;

    CLOSE R_emp;

    Return v_emp_array;

    exception

    while others then

    dbms_output.put_line (dbms_utility.format_error_stack);

    dbms_output.put_line (dbms_utility.format_call_stack);

    dbms_output.put_line (dbms_utility.format_error_backtrace);

    raise_application_error (-20001, SQLERRM);

    end;

    /

    SELECT *.

    table (f_emp ());

    a table function works with a table (nested table or varray)

    HTH

  • Inserting data in the nested table

    I explore the differences between the OBJECT and RECORD.

    As I'm still learning, I found that both are structures which essentially brings together different elements of types of different data or columns of data types, one is used in SQL and other is used in PL/SQL, please correct me if I'm wrong in my understanding.

    Below, I am trying to insert data into an array of type object, but I can't can you please help.

    CREATE OR REPLACE type sam as OBJECT
    (
    v1 NUMBER,
    v2 VARCHAR2(20 CHAR)
    );
    
    ---Nested Table---
    create or replace type t_sam as table of sam;
    
    --Inserting data----
    insert into table(t_sam) values(sam(10,'Dsouza'));
    

    Error message:

    Error starting at line 22 in command:
    insert into table(t_sam) values(sam(10,'Dsouza'))
    Error at Command Line:22 Column:13
    Error report:
    SQL Error: ORA-00903: invalid table name
    00903. 00000 -  "invalid table name"
    *Cause:    
    *Action:
    

    Ariean wrote:

    So the only purpose of the equivalent concept of SQL types of nested tables is to use one of the data types when you define an actual table?

    So-you can certainly use more that a simple "set an actual table. (I'm fairly certain that you can pass a table nested within a procedure, for example - try it, though - I'm not 100% sure on that - it just 'logic'.) If you can define a type, you can use it, pass it around, whatever.).

    Ariean wrote:

    And this nested table could be a record in SQL or object in PLSQL or simple data type (varchar number, etc.)?

    Nested tables are just like any other type of custom data. You can create a nested table of other types of data. You can create a custom of nested tables data type.

    Stupidly, he could become... uh, stupid O_0

    CREATE TYPE o_myobj1 AS object ( id1   number, cdate1  date );
    
    CREATE TYPE t_mytype1 AS table of o_myobj1;
    
    CREATE TYPE o_myobj2 AS object ( id2   number,  dumb  t_mytype1 );
    
    CREATE TYPE t_dumber AS table of o_myobj2;
    

    O_0

    OK, my brain is starting to hurt - I hope you get the idea

    Ariean wrote:

    Second is my understanding correct any OBJECT & RECORD?

    I see no benefit to describe another way.

  • wanted to extract data from nested table pl/sql Ref Cursor getting an erro

    create or replace type 'DEPT12' as an object (dno number (2), dname varchar2 (30), varchar2 (50)) loc;

    create or replace type dept_tab in the table in "DEPT12".

    create or replace type 'LOC12' as an object (locno number, loc_name varchar2 (100))

    create or replace type loc_tab in the table of "LOC12.

    create or replace type dept_loc_rec1 as an object (dept_tab, eno number, loc_dt loc_tab dept_dt);

    Create type dept_loc_tb as table of the dept_loc_rec1

    create table dept_loc_tb_bk1 (dept_dt dept_tab, eno number, loc_dt loc_tab)
    NESTED TABLE dept_dt
    STORE AS dept_tab12,
    NESTED TABLE loc_dt
    STORE AS loc_tab12




    insert into dept_loc_tb_bk1 values (dept_tab (dept12(3,'ABD','LOC')
    dept12(4,'ABD','LOC')
    (, dept12(5,'ABD','LOC')), 3, loc_tab (loc12(21,'AAB'),
    loc12(22,'AAB'),
    loc12(23,'AAB')));

    When I try to extract data from Ref cursor to pl/sql table that I get an error ora-06504: pl/sql: return types of the result set of variables or request do not match.
    I created a table nested, as well as the pl/sql nested table object dept_loc_tb and I said the same dept_loc_tb lv_dept_loc_tb, but trying to get in this variable we get an error above.

    Please anyone can solve my problem.
    -----------------
    declare
    type cr is ref cursor;
    cr_obj cr;

    lv_dept_loc_tb dept_loc_tb;

    Start
    Open cr_obj to select dept_dt, eno, dept_loc_tb_bk1 loc_dt;
    collect the fetch cr_obj in bulk in lv_dept_loc_tb;
    close cr_obj;
    end;

    Your query selects 3 distinct columns requires so 3 collections of matching types. You want to treat these 3 columns as an object of type DEPT_LOC_REC1:

    SQL> declare
      2  type cr is ref cursor;
      3  cr_obj cr;
      4
      5  lv_dept_loc_tb dept_loc_tb;
      6
      7  begin
      8  open cr_obj for select dept_dt,eno,loc_dt from dept_loc_tb_bk1;
      9  fetch cr_obj bulk collect into lv_dept_loc_tb;
     10  close cr_obj;
     11  end;
     12  /
    declare
    *
    ERROR at line 1:
    ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
    ORA-06512: at line 9
    
    SQL> declare
      2  type cr is ref cursor;
      3  cr_obj cr;
      4
      5  lv_dept_loc_tb dept_loc_tb;
      6
      7  begin
      8  open cr_obj for select DEPT_LOC_REC1(dept_dt,eno,loc_dt) from dept_loc_tb_bk1;
      9  fetch cr_obj bulk collect into lv_dept_loc_tb;
     10  close cr_obj;
     11  end;
     12  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.
    P.S. discover sys_refcursor.

  • Insert and update the nested table

    Hello

    I created a nested table containing the following columns. I need to insert records into the nested table. And also I have to update the nested table. Please find below my table and get error message.

    Please advose...!
    SQL> create type details as object(
      2  basic number(7,2),
      3  da number(6,2),
      4  hra number(6,2),
      5  pf number(6,2),
      6  it number(6,2),
      7  gross number(7,2),
      8  ded number(6,2),
      9  net number(8,2));
     10  /
    
    Type created.
    
    SQL> create type details_t is table of details;
      2  /
    
    Type created.
    
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  create table emp_tab(empno number(4),name varchar2(10),details_tab details_t)
      2* nested table details_tab store as empl_details
    SQL> /
    
    Table created.
    
    
    SQL> ed
    Wrote file afiedt.buf
    
      1* insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null)))
    SQL> /
    Enter value for empno: 1
    Enter value for name: asdf
    Enter value for da: 120
    Enter value for hra: 130
    Enter value for pf: 120
    Enter value for it: 120
    old   1: insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null
    new   1: insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null)))
    insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null)))
                                                 *
    ERROR at line 1:
    ORA-02315: incorrect number of arguments for default constructor
    Can I use '&' while inserting records in the nested table? Yes / No?

    I do need to update also net gross, ded, columns... !!

    Please help me... !!

    Concerning
    A
    $ sqlplus scott/tiger
    
    SQL*Plus: Release 10.2.0.2.0 - Production on Thu Apr 21 16:18:16 2011
    
    Copyright (c) 1982, 2005, Oracle.  All Rights Reserved.
    
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    
    SQL> CREATE TYPE details AS OBJECT(
     basic NUMBER(7,2),
     da NUMBER(6,2),
     hra NUMBER(6,2),
     pf NUMBER(6,2),
     it NUMBER(6,2),
     gross NUMBER(7,2),
     ded NUMBER(6,2),
     net NUMBER(8,2));  2    3    4    5    6    7    8    9
     10  /
    
    Type created.
    
    SQL> CREATE TYPE details_t IS TABLE OF details;
      2  /
    
    Type created.
    
    SQL> CREATE TABLE emp_tab(empno NUMBER(4),name VARCHAR2(10),details_tab details_t)
     NESTED TABLE details_tab store as empl_details  2
      3  /
    
    Table created.
    
    SQL> INSERT INTO emp_tab VALUES(7001,'Saubhik',details_t(details(100,100,50,10,10,null,null,null)));
    
    1 row created.
    
    SQL> SELECT * FROM TABLE (SELECT details_tab FROM emp_tab WHERE empno=7001);
    
         BASIC         DA        HRA         PF         IT      GROSS        DED
    ---------- ---------- ---------- ---------- ---------- ---------- ----------
           NET
    ----------
           100        100         50         10         10
    
    SQL> ^C
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  UPDATE TABLE (SELECT details_tab FROM emp_tab WHERE empno=7001)
      2     emp_sal
      3*    SET emp_sal.net=emp_sal.basic+emp_sal.da+emp_sal.hra
    SQL> /
    
    1 row updated.
    
    SQL> SELECT * FRM emp_tab;
    SELECT * FRM emp_tab
             *
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    
    SQL> SELECT * FROM emp_tab;
    
         EMPNO NAME
    ---------- ----------
    DETAILS_TAB(BASIC, DA, HRA, PF, IT, GROSS, DED, NET)
    --------------------------------------------------------------------------------
          7001 Saubhik
    DETAILS_T(DETAILS(100, 100, 50, 10, 10, NULL, NULL, 250))
    
    SQL>
    
  • Question: insertion of several lines in the MS Sql Server table using the DB adapter

    Hi all

    I managed to insert a single row in a table of MS SQL Server via the adapter DB to my process BPEL, but when I tried to insert in mutiple lines in the same table of MS SQL server, I encounter the error below.

    I use a DB SQL XA connection to connect to the server.

    Kindly help me to solve the problem. Thanks in advance.

    Error:

    " < bpelFault > < faultType > 0 < / faultType > < remoteFault xmlns =" http://schemas.Oracle.com/BPEL/extension "> < a name ="summary"part > < summary > exemption is is produced when the binding was used." Exception occurred during invocation of the JCA binding: "JCA binding run 'merge' reference operations have to: DBWriteInteractionSpec Execute Failed Exception." the merger failed. The descriptor name: [LoadCmpAggSpendStage.SapTable]. Caused by com.microsoft.sqlserver.jdbc.SQLServerException: incorrect syntax near ')'... Check the logs for the record output full DBAdapter before this exception. This exception is considered as reproducible, probably due to a communication failure. To be classified as not reproducible rather add property nonRetriableErrorCodes with the '102' value in the deployment descriptor (i.e. weblogic - RA.Xml). Auto retry a reproducible fault set composite.xml for this invoke these properties: jca.retry.interval, jca.retry.count and jca.retry.backoff. All properties are integers. ". The called JCA adapter threw an exception of resource. Please examine the error message above carefully to determine a resolution. < /Summary. (> < / piece > < part name = "detail" > < detail syntax > incorrect near ')'. < / details > < / piece > < part name = "code" > < code > 102 < / code > < / piece > < / remoteFault > < / bpelFault >

    Kind regards

    Balaji Rahmani

    It seems that in this case is called merge operation. If existing records (check primary key) are not there then it will be inserted on the other update. Check the syntax of the query that is created. It looks like she may have a supplement "). If you want to only insert then call insert operation and not merge.

  • Question simple quue PL/SQL nested tables

    Hello, my question is about nested tables. Suppose I have a nested table:
    Int_array ARRAY TYPE IS INT;
    v_int_array int_array;

    Is there a built in function for me to v_int_array for a specific integer search value?

    George

    MEMBER of operator use:

    declare
        TYPE int_array IS TABLE OF INT;
        v_int_array int_array := int_array(1,2,3,4,5);
    begin
        if 1 member of v_int_array
          then
            dbms_output.put_line('Found it!');
        end if;
    end;
    /
    Found it!
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Oracle 9 error: insert into temp-table collection (nested table)

    Hello everyone

    I have an urgent problem. I have a package which has been developed against 10g but must now be deployed on 9i as well. I don't use 10 g - features and packages compile well on 9.

    Somehow, I get the following runtime error: failed execution: ORA-22905: cannot access the rows of a no nested table item.

    The Code I use to the particular line is

    insert into tmp_report_calculation (select from table (calculations)); *

    tmp_report_calculation is a temporary table and calculations holds a collection type that is a nested table. I do not understand why the error is complaining about "No nested table. Less than 10g everything run took place.

    Can someone help me out here? Furthermore, it is important that I put the results in this temp-table (since I can't use the multiset on Oracle 9)

    concerning
    -Marc

    Try

    insert into tmp_report_calculation (select * from table(cast(calculations as your_collection_type)));
    

    replace"your_collection_type" with your name in the actual collection of course...

  • Compare the content of two equal nested tables

    I'm working on a black box test where I compare the contents of two structurally equal tables before and after executing a script of some. My two tables, MDQ_OLD and MDQ_NEW, are filled with the data in two separate operations.

    The two tables, I'll compare are nested, as you can see in the CREATE TABLE scripts below.

    I tried to use the less-operator sign, but without success.

    I also tried to select data in a type that is % ROWTYPE to my nested tables, but it does not work as well (see the below script in this post).

    Can you please help me on this problem on how to compare the content of two nested tables?

    Run the scripts below to reproduce the problem and be sure to update this post if more information is required.

    -The scripts below-

    Select * from version of v$.

    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production

    PL/SQL Release 11.2.0.4.0 - Production

    CORE Production 11.2.0.4.0

    AMT for Linux: Version 11.2.0.4.0 - Production

    NLSRTL Version 11.2.0.4.0 - Production

    -First of all, I create my types

    CREATE OR REPLACE TYPE FORCE AS OBJECT MDQ_DETAIL (NUMBER OF MDQ_DETAIL_ID, MDQ_DETAIL_DESC VARCHAR2 (100));

    CREATE OR REPLACE TYPE T_MDQ_DETAIL AS TABLE MDQ_DETAIL;

    -Note that this type contains the table T_MDQ_DETAIL type:

    CREATE OR REPLACE TYPE MDQ_PARENT FORCE AS OBJECT (NUMBER MDQ_ID, MDQ_DETAILS T_MDQ_DETAIL);

    - Then I create two equal nested tables

    CREATE THE NESTED TABLE AS MDQ_PR_OLD STORE MDQ_DETAILS MDQ_PARENT MDQ_OLD TABLE.

    CREATE THE NESTED TABLE AS MDQ_PR_NEW STORE MDQ_DETAILS MDQ_PARENT MDQ_NEW TABLE.

    -Insert test data in the nested tables

    Insert into MDQ_OLD (MDQ_ID, MDQ_DETAILS) Values (1, T_MDQ_DETAIL (MDQ_DETAIL(1,'desc1')));

    Insert into MDQ_NEW (MDQ_ID, MDQ_DETAILS) Values (2, T_MDQ_DETAIL (MDQ_DETAIL(1,'desc1')));

    -Try to use the negative operator to compare the contents of the trailer of the nested tables, but it gives this error:

    -ORA-00932: inconsistent data types: expected - got DISPATCH. T_MDQ_DETAIL

    Select * from MDQ_NEW

    less

    Select * from MDQ_OLD;

    -Try to select in a ROWTYPE, but it fails

    declare

    myTypeOld MDQ_OLD % ROWTYPE;

    myTypeNew MDQ_New % ROWTYPE;

    myTypeDiff MDQ_New % ROWTYPE;

    Start

    -Select gives: PLS-00497: do not mix between row and several rows (in BULK) list

    Select * bulk collect into mdq_old myTypeOld;

    Select * bulk collect into mdq_new myTypeNew;

    -Need a 'compare the function of membership card' on the types of multiset except to work, but as far as I

    -I'm not able to bulk collect into myTypeOld or myTypeNew, this won't help out me.

    myTypeDiff: = multiset myTypeOld except myTypeNew.

    end;

    -Cleaning:

    drop table MDQ_OLD;

    drop table MDQ_NEW;

    type of projection MDQ_PARENT;

    type of projection T_MDQ_DETAIL;

    type of projection MDQ_DETAIL;

    > queries you provided intercepts not who.

    You asked how to compare the content of nested tables.

    I knew that you didn't ask for what you actually want, that's why I asked you to specify the comparison more in detail.

    > Do you have a query that grabs this difference as well?

    SELECT o.mdq_id, od.*
    OF mdq_old o, TABLE (o.mdq_details) od
    LESS
    SELECT n.mdq_id, nd.*
    OF mdq_new n, TABLE (n.mdq_details) nd;

    > Also, if possible, do you have a sample of a statement to COLLECT LOOSE, please?

    Actually, you raise an interesting point on using % ROWTYPE, in my view, that should be. This make...

    DECLARE
    TYPE rt_mdq_new () IS RENDERING
    mdq_id NUMBER,
    mdq_details t_mdq_detail);
         
    TYPE tt_mdq_new IS TABLE OF THE rt_mdq_new;
      
    t_mdq_new tt_mdq_new;
    BEGIN
    SELECT mdq_id, mdq_details
    LOOSE COLLECTION t_mdq_new
    OF mdq_new min.;
    END;
    /

    DECLARE
    CURSOR c_mdq_new
    IS
    SELECT mn.*
    OF mdq_new min.;
         
    TYPE tt_mdq_new IS TABLE OF c_mdq_new % ROWTYPE;
      
    t_mdq_new tt_mdq_new;
    BEGIN
    OPEN c_mdq_new.
    Get the c_mdq_new COLLECT in BULK IN t_mdq_new;
    CLOSE C_mdq_new;
    END;
    /

  • Merge into the nested table

    Hi all
    Can I combine the records in the nested table
    I have a table with 2 colum: col_1 and col_2
    col_1: corresponds to the id (varchar2)
    col_2: is a column nested with the type of table (sub_col_1 (number), sub_col_2 (number))

    for example: I have 2 accounts table ('a', (1,2)) and ('b', (3,4)))

    what I want is merged into this table with values ('a', '4.5')) + ('c', (6,7)) IN a single statement

    What I should have after this operation ('a', (1,2,4,5)) + ('b', (3,4)) + ('c', (6,7)).
    Can I do this?
    CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT(SUB_COL_1 NUMBER, SUB_COL_2 NUMBER) ;
    
    CREATE OR REPLACE TYPE TEST_TYPE_TABLE IS TABLE OF TEST_TYPE;
    
    CREATE TABLE TEST_MERGE_NESTED_TABLE (COL_1 VARCHAR2(1 CHAR), COL_2 TEST_TYPE_TABLE)
        NESTED TABLE COL_2 STORE AS COL_2_NESTED;
        
    INSERT INTO TEST_MERGE_NESTED_TABLE VALUES('a',TEST_TYPE_TABLE(TEST_TYPE(1,2) ));
    INSERT INTO TEST_MERGE_NESTED_TABLE VALUES('b',TEST_TYPE_TABLE(TEST_TYPE(3,4) ));
    Oracle version: 11.2.0.3
    Thank you all.

    Published by: 966205 on 20:18 21/02/2013

    Published by: 966205 on 20:42 21/02/2013

    966205 wrote:
    That means he does the same thing as what I want (adding? do not recreate this column in the physical layer).

    Actually, no.
    All content of the nested table is first removed (for the given FK), then the result of the MULTISET UNION is reinserted.

    The evidence on:

    SQL> alter session set events '10046 trace name context forever, level 12';
    
    Session altered.
    
    SQL> merge into test_merge_nested_table t
      2  using (
      3    select 'a' col_1, TEST_TYPE_TABLE(TEST_TYPE(4,5)) col_2 from dual union all
      4    select 'c' , TEST_TYPE_TABLE(TEST_TYPE(6,7))            from dual
      5  ) v
      6  on ( t.col_1 = v.col_1 )
      7  when matched then update
      8    set t.col_2 = t.col_2 multiset union v.col_2
      9  when not matched then insert (col_1, col_2)
     10   values (v.col_1, v.col_2) ;
    
    2 rows merged.
    
    SQL> alter session set events '10046 trace name context off';
    
    Session altered.
    
    SQL> select * from test_merge_nested_table;
    
    C COL_2(SUB_COL_1, SUB_COL_2)
    - --------------------------------------------------------------------------------
    c TEST_TYPE_TABLE(TEST_TYPE(6, 7))
    a TEST_TYPE_TABLE(TEST_TYPE(1, 2), TEST_TYPE(4, 5))
    b TEST_TYPE_TABLE(TEST_TYPE(3, 4))
    

    TKPROF output:

    DELETE, the nested table statement objectives associated with 'a' and deletes the line after line that it contains (1,2).
    The later INSERTION is performed twice (run count = 2) and target the two nested table 'a' by inserting 2 ranks: former one (1,2) + the new one (4.5) and the nested table 'c' by inserting 1 row (6,7).

    SQL ID: 6bjc2z2t53csn Plan Hash: 132214516
    
    DELETE /*+ REF_CASCADE_CURSOR */ FROM "DEV"."COL_2_NESTED"
    WHERE
     "NESTED_TABLE_ID" = :1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          1          3           1
    Fetch        0      0.00       0.00          0          0          0           0
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        2      0.00       0.00          0          1          3           1
    
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: SYS   (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             0          0          0  DELETE  COL_2_NESTED (cr=1 pr=0 pw=0 time=44 us)
             1          1          1   INDEX RANGE SCAN SYS_FK0000023444N00002$ (cr=1 pr=0 pw=0 time=10 us)(object id 23446)
    
    ********************************************************************************
    
     
    
    ********************************************************************************
    
    SQL ID: 0fzd5yk23jyas Plan Hash: 0
    
    INSERT /*+ NO_PARTIAL_COMMIT REF_CASCADE_CURSOR */ INTO "DEV"."COL_2_NESTED"
      ("NESTED_TABLE_ID","SYS_NC_ROWINFO$")
    VALUES
    (:1, :2)
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        2      0.00       0.00          0          0          0           0
    Execute      2      0.00       0.00          0          2         10           3
    Fetch        0      0.00       0.00          0          0          0           0
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        4      0.00       0.00          0          2         10           3
    
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             0          0          0  LOAD TABLE CONVENTIONAL  (cr=1 pr=0 pw=0 time=113 us)
    
    ********************************************************************************
    
  • How to assign values to the nested table and passes as a parameter for the procedure?

    How to assign values to the nested table and passes as a parameter for the procedure?

    Here are the object and its type

    create or replace type test_object1 as an object
    (
    val1 varchar2 (50).
    val2 varchar2 (50).
    VARCHAR2 (50) val3
    );


    create or replace type test_type1 is table of the test_object1;


    create or replace type test_object2 as an object
    (
    val1 varchar2 (50).
    val2 varchar2 (50).
    VARCHAR2 (50) val3
    );


    create or replace type test_type2 is table of the test_object2;


    GRANT ALL ON test_object1 to PUBLIC;


    GRANT ALL ON test_type1 to PUBLIC;


    GRANT ALL ON test_object2 to PUBLIC;


    GRANT ALL ON test_type2 to PUBLIC;

    Here is the table object type:

    create the table test_object_tpe
    (
    sl_num NUMBER,
    Description VARCHAR2 (100),
    main_val1 test_type1,
    main_val2 test_type2
    )


    NESTED TABLE main_val1 STORE AS tot1
    NESTED TABLE main_val2 STORE AS earlier2;


    -----------------------------------------------------------------------------------------------------------

    Here is the procedure that inserts values into the nested table:

    PROCEDURE INSERT_TEST_DATA (sl_num in NUMBER,
    Description in VARCHAR2,
    p_main_val1 IN test_type1,
    p_main_val2 IN test_type2
    )
    IS
    BEGIN

    FOR rec in p_main_val1.first... p_main_val1. Last
    LOOP

    INSERT INTO xxdl.test_object_tpe
    (
    sl_num,
    Description,
    main_val1,
    main_val2
    )
    VALUES
    (
    sl_num
    description
    test_type1 (test_object1)
    p_main_val1 .val1 (CRE),
    p_main_val1 .val2 (CRE),
    p_main_val1 .val3 (rec)
    )
    )
    test_type2 (test_object2 (p_main_val2 .val1 (CRE),
    p_main_val2 .val2 (CRE),
    p_main_val2 .val3 (rec)
    )
    )

    );

    END LOOP;

    commit;

    END INSERT_TEST_DATA;

    -------------------------------------------------------------------------------------------

    Here are the block anonymoys what values attributed to the object type and pass values in the procedure:

    Set serveroutput on;

    declare

    p_sl_num NUMBER: = 1001;
    p_description VARCHAR2 (50): = 'Test Val1;

    inval1 test_type1: = test_type1();
    inval2 test_type2: = test_type2();

    Start


    inval1 (1) .val1: = "testx1";
    inval1 (1) .val2: = "testx2";
    inval1 (1) .val3: = "testx3";

    inval2 (1) .val1: = "testy1";
    inval2 (1) .val2: = "testy2";
    inval2 (1) .val3: = "testy3";

    CSI_PKG. INSERT_TEST_DATA (sl_num = > p_sl_num,)
    Description = > p_description,
    p_main_val1 = > inval1,
    p_main_val2 = > inval2
    );

    end;
    /
    Someone can correct me.

    Thank you
    Lavan

    Thanks for posting the DOF and the sample code but whenever you post provide your Oracle version 4-digit (result of SELECT * FROM V$ VERSION).
    >
    How to assign values to the nested table and passes as a parameter for the procedure?
    >
    Well you do almost everything bad that could be hurt.

    Here is the code that works to insert data into your table (the procedure is not even necessary).

    declare
    p_sl_num NUMBER := 1001;
    p_description VARCHAR2(50) := 'Testing Val1';
    inval1 test_type1 := test_type1();
    inval2 test_type2 := test_type2();
    begin
    inval1.extend();
    inval1(1) := test_object1('testx1', 'testx2', 'testx3');
    inval2.extend();
    inval2(1) := test_object2('testy1', 'testy2', 'testy3');
    
    INSERT INTO test_object_tpe
    (
    sl_num,
    description,
    main_val1,
    main_val2
    )
    VALUES
    (p_sl_num, p_description, inval1, inval2);
    commit;
    end;
    /
    

    See example 5-15 making reference to an element of nested Table Chapter 5 using PL/SQL collections and records in the PL/SQL doc
    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/Collections.htm#CJABEBEA

    1. you don't even have the procedure because it is a simple INSERTION in the table you can do directly (see my above code)

    inval1(1).val1 := 'testx1';
    

    Since you have not yet created all the elements, there is no element 1 "inval1". You need EXTEND the collection to add an element

    inval1.extend();
    

    And then, there is an empty element, but "inval1" is a container for objects of type 'test_object1' not for scalars as "val1", "val2", and "val3".
    If you can not do

    inval1(1).val1 := 'testx1';
    

    You must create an instance of 'test_object1 '.

    inval1(1) := test_object1('testx1', 'testx2', 'testx3');
    

    And so on for the other collection

    You don't need the procedure (as my code example shows), but once you fill in the variables correctly it will work.

  • Query a nested table of sdo_geometry

    I have the following situation in the my database:
    -----
    SQL > drop type obj_type1 force;
    create or replace TYPE obj_type1 AS OBJECT (id integer, geom sdo_geometry);

    Drop type obj_type2 force;
    create or replace TYPE obj_type2 AS OBJECT (id integer, m obj_type1);

    Drop type geom_tab force;
    create or replace TYPE geom_tab AS table obj_type2;

    drop table tab1;
    create table tab1 (name varchar2 (40), geom_info geom_tab) store geom_info table nested as geom_nt;

    -Inserting data
    insert into tab1 values ('1', geom_tab)
    obj_type2 (1, obj_type1 (1, MDSYS.) SDO_GEOMETRY (2002, NULL, NULL, MDSYS.) SDO_ELEM_INFO_ARRAY (1,2,1), MDSYS. SDO_ORDINATE_ARRAY (2804.31, 12678.5, 12679.2, 2832.08))),
    obj_type2 (2, obj_type1 (2, MDSYS.) SDO_GEOMETRY (2002, NULL, NULL, MDSYS.) SDO_ELEM_INFO_ARRAY (1,2,1), MDSYS. SDO_ORDINATE_ARRAY (2832.08, 12677.9, 12678.5, 2859.85)));
    insert into tab1 values ('2', geom_tab)
    obj_type2 (1, obj_type1 (1, MDSYS.) SDO_GEOMETRY (2002, NULL, NULL, MDSYS.) SDO_ELEM_INFO_ARRAY (1,2,1), MDSYS. SDO_ORDINATE_ARRAY (2859.85, 12677.3, 12677.9, 2887.63))),
    obj_type2 (2, obj_type1 (MDSYS. SDO_GEOMETRY (2002, NULL, NULL, MDSYS.) SDO_ELEM_INFO_ARRAY (1,2,1), MDSYS. SDO_ORDINATE_ARRAY (2887.63, 12676.7, 12677.3, 2915.4)));
    -update of metadata
    INSERT INTO user_sdo_geom_metadata
    (TABLE_NAME,
    COLUMN_NAME,
    DIMINFO,
    SRID)
    VALUES)
    'geom_nt', - name of the nested table
    "m.geom,"
    MDSYS. SDO_DIM_ARRAY (MDSYS. SDO_DIM_ELEMENT ('X',-9267, 28329, 5-7), MDSYS. SDO_DIM_ELEMENT('Y',-2598,26587,5E-7)),
    NULL - SRID VALUE
    );
    commit;
    -creation of a spatial index
    create index geom_ump_idx1 on geom_nt (m.geom) INDEXTYPE IS MDSYS. SPATIAL_INDEX;
    -another table to the query
    create the table querypointss (geometry sdo_geometry);
    INSERT INTO user_sdo_geom_metadata
    (TABLE_NAME,
    COLUMN_NAME,
    DIMINFO,
    SRID)
    VALUES)
    'querypointss', - name of the nested table
    "geometry."
    MDSYS. SDO_DIM_ARRAY (MDSYS. SDO_DIM_ELEMENT ('X',-9267, 28329, 5-7), MDSYS. SDO_DIM_ELEMENT('Y',-2598,26587,5E-7)),
    NULL - SRID VALUE
    );
    Insert values (querypointss)
    MDSYS. SDO_GEOMETRY (2001, NULL, MDSYS.) SDO_POINT_TYPE (4224.0,6828.0,NULL), NULL, NULL));
    commit;
    -The following query works fine
    SELECT *.
    OF tab1 C, table (c.geom_info) tt, PP querypointss
    WHERE mdsys.sdo_anyinteract (tt.m.geom,
    MDSYS. SDO_GEOMETRY (2002, NULL, NULL, MDSYS.) SDO_ELEM_INFO_ARRAY (1,2,1), MDSYS. SDO_ORDINATE_ARRAY (2859.85, 12677.3, 12677.9, 2887.63))
    ) = "TRUE";
    - But when the second argument of the sdo_anyinteract is a column in a table, it will not work
    SELECT *.
    OF tab1 C, table (c.geom_info) tt, PP querypointss
    WHERE mdsys.sdo_anyinteract (tt.m.geom,
    PP.geometry
    ) = "TRUE";
    -----
    and he returned this error:
    Error report:
    SQL error: ORA-13268: error to get the dimension of the USER_SDO_GEOM_METADATA
    ORA-06512: at the 'MDSYS. MD", line 1723
    ORA-06512: at the 'MDSYS. MDERR", line 8
    ORA-06512: at the 'MDSYS. SDO_3GL", line 132
    ORA-06512: at the 'MDSYS. SDO_3GL', line 256
    13268 00000 - «Error get the dimension of the USER_SDO_GEOM_METADATA»
    * Cause: There is no entry in the USER_SDO_GEOM_METADATA view for the specified
    table of geometry.
    * Action: Insert an entry for the destination geometry table with
    correct size information.

    What is
    / * + foreground (pp tt) use_nl (pp tt) use_index (tt geom_ump_idx1) * /.

    or

    / * + leading (pp tt) USE_NL_WITH_INDEX (tt geom_ump_idx1) * /.

  • order of the elements in the nested tables

    In PL/SQL when I add item to a nested table of objects one by one (in order), and then try to insert that litter table type to a physical table, the change element order. How can I avoid this behavior?

    When you use the columns collection or object tables, nested tables are not guaranteed to hold the control element. varraying arrays (varrays), however, are.

    Also note that if you use the view object (or with columns in the collection), your SQL view materializes the collection and you can return any desired way (whether or not it is classified).

    I hope this helps...

    Gerard

Maybe you are looking for

  • How to apply to market when the fact that the process?

    Yesterday my firefox worked fine, but now when I click on one of my shortcuts, nothing happens. When I opened my task manager, I see the firefox.exe process is turned on but not the actual application. I tried to make it work for two hours. I reboote

  • Remote DST does not properly now?

    Re: Model R7300DST The router and DST were installed/setup by Geek squad on 16 January. Everything worked fine until a month ago when I noticed that if I changed WiFi points from the router to the DST, the device tries to connect but not. I powered t

  • How to manage the data after the serial com port?

    Hi all I'm new to labview and serial communication. I tried to receive data on external device labview (pic18f452). It's done, but I am getting data as strings. If microcontroller gives "11.25", in labview each letter is delivered to a different as s

  • Error: "cannot open Volume for Direct access" is displayed when Chkdsk runs at startup

    Original title: Edit/Fix key in my registry CHKDSK keeps trying to run during startup, but "cannot open volume...". "If I can solve this problem, I want to put it in the manual, not automatic.      My registry key: "HKEY_LOCAL_MACHINE\SYSTEM\CurrentC

  • Animate Adobe install, on the contrary, it installs CS6

    So I just got a new PC (Windows 8) and I'm trying to download Adobe animate CC 2015, so I go to the apps page, it says "Adobe animate CC 2015" and I click on the download button. But instead of download Adobe animate, it installs Adobe Flash CS6 and