How to DEREF a nested Table of REFs?

Can someone provide an example of how to deference, DEREF, a nested table of refs? (i.e. in order to access the attributes of the objects whose references appear in the nested table)
I'm creating object views based on relational tables. One of my object views contains a nested table of refs which represents a FK relationship, (1:M).
We're running ORACLE 8.1.7
EXAMPLE DDL:
/* FORWARD DECLARATIONS SO THINGS COMPILE */
CREATE TYPE TEST_DAY_T AS OBJECT
CREATE TYPE TEST_SECTION_T AS OBJECT
/* COLLECTION TYPES */
CREATE OR REPLACE
TYPE TEST_SECTION_REFTAB_T AS TABLE OF REF TEST_SECTION_T
/* OBJECT TYPES */
CREATE OR REPLACE
TYPE TEST_DAY_T AS OBJECT
(TEST_ID NUMBER(12)
,TEST_DAY NUMBER(1)
,TEST_SECTIONS TEST_SECTION_REFTAB_T
CREATE OR REPLACE
TYPE TEST_SECTION_T AS OBJECT
(TEST_ID NUMBER(12)
,TEST_DAY NUMBER(1)
,SECTION_SEQ NUMBER(3)
,SECTION_NAME VARCHAR2(32)
/* TABLE DEFS */
CREATE TABLE test_day
test_id NUMBER(12) NOT NULL,
test_day NUMBER(1) NOT NULL
ALTER TABLE test_day
ADD CONSTRAINT test_day_pk PRIMARY KEY (test_id,test_day)
CREATE TABLE test_section
test_id NUMBER(12) NOT NULL,
test_day NUMBER(1) NOT NULL,
section_seq NUMBER(3) NOT NULL,
section_name VARCHAR2(32) NOT NULL
ALTER TABLE test_section
ADD CONSTRAINT test_section_pk PRIMARY KEY (test_id,test_day,section_seq)
ALTER TABLE test_section
ADD CONSTRAINT test_section_fk01 FOREIGN KEY (test_id,test_day)
REFERENCES TEST_DAY(test_id,test_day)
/* OBJECT VIEWS */
CREATE OR REPLACE VIEW v_test_section_obj
OF TEST_SECTION_T
WITH OBJECT OID (TEST_ID, TEST_DAY, SECTION_SEQ)
AS
SELECT TS.TEST_ID,
TS.TEST_DAY,
TS.SECTION_SEQ,
TS.SECTION_NAME
FROM TEST_SECTION TS
CREATE OR REPLACE VIEW v_test_day_obj
OF TEST_DAY_T
WITH OBJECT OID (TEST_ID, TEST_DAY)
AS
SELECT TD.TEST_ID,
TD.TEST_DAY,
CAST(MULTISET(SELECT ref(tso)
FROM v_test_section_obj tso
WHERE tso.test_id = td.test_id
AND tso.test_day = td.test_day) AS TEST_SECTION_REFTAB_T)
FROM TEST_DAY TD
/* CLEANUP */
DROP VIEW v_test_day_obj
DROP VIEW v_test_section_obj
DROP TYPE TEST_SECTION_REFTAB_T
DROP TYPE TEST_DAY_T
DROP TYPE TEST_SECTION_T
DROP TABLE TEST_SECTION
DROP TABLE TEST_DAY

Martin,
You can check out an example online at http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96594/adobjvew.htm#436463.
Regards,
Geoff
Can someone provide an example of how to deference, DEREF, a nested table of refs? (i.e. in order to access the attributes of the objects whose references appear in the nested table)
I'm creating object views based on relational tables. One of my object views contains a nested table of refs which represents a FK relationship, (1:M).
We're running ORACLE 8.1.7
EXAMPLE DDL:
/* FORWARD DECLARATIONS SO THINGS COMPILE */
CREATE TYPE TEST_DAY_T AS OBJECT
CREATE TYPE TEST_SECTION_T AS OBJECT
/* COLLECTION TYPES */
CREATE OR REPLACE
TYPE TEST_SECTION_REFTAB_T AS TABLE OF REF TEST_SECTION_T
/* OBJECT TYPES */
CREATE OR REPLACE
TYPE TEST_DAY_T AS OBJECT
(TEST_ID NUMBER(12)
,TEST_DAY NUMBER(1)
,TEST_SECTIONS TEST_SECTION_REFTAB_T
CREATE OR REPLACE
TYPE TEST_SECTION_T AS OBJECT
(TEST_ID NUMBER(12)
,TEST_DAY NUMBER(1)
,SECTION_SEQ NUMBER(3)
,SECTION_NAME VARCHAR2(32)
/* TABLE DEFS */
CREATE TABLE test_day
test_id NUMBER(12) NOT NULL,
test_day NUMBER(1) NOT NULL
ALTER TABLE test_day
ADD CONSTRAINT test_day_pk PRIMARY KEY (test_id,test_day)
CREATE TABLE test_section
test_id NUMBER(12) NOT NULL,
test_day NUMBER(1) NOT NULL,
section_seq NUMBER(3) NOT NULL,
section_name VARCHAR2(32) NOT NULL
ALTER TABLE test_section
ADD CONSTRAINT test_section_pk PRIMARY KEY (test_id,test_day,section_seq)
ALTER TABLE test_section
ADD CONSTRAINT test_section_fk01 FOREIGN KEY (test_id,test_day)
REFERENCES TEST_DAY(test_id,test_day)
/* OBJECT VIEWS */
CREATE OR REPLACE VIEW v_test_section_obj
OF TEST_SECTION_T
WITH OBJECT OID (TEST_ID, TEST_DAY, SECTION_SEQ)
AS
SELECT TS.TEST_ID,
TS.TEST_DAY,
TS.SECTION_SEQ,
TS.SECTION_NAME
FROM TEST_SECTION TS
CREATE OR REPLACE VIEW v_test_day_obj
OF TEST_DAY_T
WITH OBJECT OID (TEST_ID, TEST_DAY)
AS
SELECT TD.TEST_ID,
TD.TEST_DAY,
CAST(MULTISET(SELECT ref(tso)
FROM v_test_section_obj tso
WHERE tso.test_id = td.test_id
AND tso.test_day = td.test_day) AS TEST_SECTION_REFTAB_T)
FROM TEST_DAY TD
/* CLEANUP */
DROP VIEW v_test_day_obj
DROP VIEW v_test_section_obj
DROP TYPE TEST_SECTION_REFTAB_T
DROP TYPE TEST_DAY_T
DROP TYPE TEST_SECTION_T
DROP TABLE TEST_SECTION
DROP TABLE TEST_DAY

Similar Messages

  • How to insert into a table with a nested table which refer to another table

    Hello everybody,
    As the title of this thread might not be very understandable, I'm going to explain it :
    In a context of a library, I have an object table about Book, and an object table about Subscriber.
    In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
    And finally, this nested table refers to the Book table.
    Here the code concerning the creation of theses tables :
    Book :
    create or replace type TBook as object
    number int,
    title varchar2(50)
    Loan :
    create or replace type TLoan as object
    book ref TBook,
    loaning_date date
    create or replace type NTLoan as table of TLoan;
    Subscriber :
    create or replace type TSubscriber as object
    sub_id int,
    name varchar2(25)
    loans NTLoan
    Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
    insert into OSubscriber values
    *(1, 'LEVEQUE', NTLoan(*
    select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
    Of course, there is an occurrence of book in the table OBook with the number attribute 1.
    Oracle returned me this error :
    SQL error : ORA-00936: missing expression
    00936. 00000 - "missing expression"
    Thank you for your help

    1) NUMBER is a reserved word - you can't use it as identifier:
    SQL> create or replace type TBook as object
      2  (
      3  number int,
      4  title varchar2(50)
      5  );
      6  /
    Warning: Type created with compilation errors.
    SQL> show err
    Errors for TYPE TBOOK:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    3/1      PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
    SQL> create table OSubscriber of TSubscriber
      2  nested table loans store as loans
      3  /
    Table created.
    SQL> create table OBook of TBook
      2  /
    Table created.
    SQL> insert
      2    into OBook
      3    values(
      4           1,
      5           'No Title'
      6          )
      7  /
    1 row created.
    SQL> commit
      2  /
    Commit complete.
    SQL> insert into OSubscriber
      2    values(
      3           1,
      4           'LEVEQUE',
      5           NTLoan(
      6                  (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
      7                 )
      8          )
      9  /
    1 row created.
    SQL> select  *
      2    from  OSubscriber
      3  /
        SUB_ID NAME
    LOANS(BOOK, LOANING_DATE)
             1 LEVEQUE
    NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
    SQL> SY.

  • HOW TO PLAY WITH NESTED TABLES

    Hi Sir,
    It would be pleasure to get any suggestion to know why i am geting following error and how to solve this problem ?
    Error Message: JBO-27122: SQL error during statement preparation. Statement: SELECT REF(ExperienceTab), ExperienceTab.SYS_NC_OID$ FROM EXPERIENCE_TAB ExperienceTab
    SCENERIO IS LIKE : I m trying to create Business Components .JSP Appl using wizard and then select view objects which has nested table. it is generated successful.
    NOW when i try to run it is executing without any errors but it doesn't show any object of nested table. THEN i decide to select nested tables to generate ViewObjects of business components and then generate .JSP file but when i try to execute application to see the result of .JSP pages which has been generated by viewobjects. And this viewobject is generated by the nested tables the above error occurs. I am quite new in Jdev enviornment , your suggestion will be higly appreciated.
    I hope my explaination is sufficient to know problem.
    Thank you very much.
    Musahib : [email protected]
    null

    Hi Sir,
    It would be pleasure to get any suggestion to know why i am geting following error and how to solve this problem ?
    Error Message: JBO-27122: SQL error during statement preparation. Statement: SELECT REF(ExperienceTab), ExperienceTab.SYS_NC_OID$ FROM EXPERIENCE_TAB ExperienceTab
    SCENERIO IS LIKE : I m trying to create Business Components .JSP Appl using wizard and then select view objects which has nested table. it is generated successful.
    NOW when i try to run it is executing without any errors but it doesn't show any object of nested table. THEN i decide to select nested tables to generate ViewObjects of business components and then generate .JSP file but when i try to execute application to see the result of .JSP pages which has been generated by viewobjects. And this viewobject is generated by the nested tables the above error occurs. I am quite new in Jdev enviornment , your suggestion will be higly appreciated.
    I hope my explaination is sufficient to know problem.
    Thank you very much.
    Musahib : [email protected]
    null

  • How to join PLSQL nested table with normal tables ?

    my requirement is to delete the rows in a normal oracle table in one statement, based on the values collected in a PL/SQL nested table which is filled by another program.
    In the following example, i need to delete the rows in
    the table c_journals where the columns branch_code and
    id are having values which exist in the PL/SQL
    nested table's columns a and b respectively
    declare
    type test_type IS RECORD (a VARCHAR2(20), b number(20));
    type test_table is table of test_type index by binary_integer;
    test_object test_table;
    cnt number;
    begin
    test_object(1).a := '1000';
    test_object(1).b := 1;
    test_object(2).a := '1006';
    test_object(2).b := 4;
    /* to be completed */
    delete c_journals where ....
    end;
    Is this possible in Oracle ? Iam using the version 9iR2
    Thanks in advance

    Both of the following delete statements should work. For the second the two types need to be created as database objects.
    declare
      type test_type IS RECORD (a VARCHAR2(20), b number(20));
      type test_table is table of test_type index by binary_integer;
      test_object test_table;  -- := test_table(test_type('1000',1), test_type('1006',4));
      cnt number;
    begin
      test_object(1).a := '1000';
      test_object(1).b := 1;
      test_object(2).a := '1006';
      test_object(2).b := 4;
      for i in test_object.first .. test_object.last loop
        delete from c_journals cj
        where test_object(i).a = cj.branch_code
         and test_object(i).b = cj.id;
      end loop;
    end;
    create or replace type test_type IS object (a VARCHAR2(20), b number(20));
    create or replace type test_table is table of test_type;
    declare
      test_object test_table := test_table(test_type('1000',1), test_type('1006',4));
      cnt number;
    begin
      delete from c_journals cj
      where exists (select 'x' from table(cast(test_object as test_table)) t
         where cj.branch_code = t.a and cj.id = t.b);
    end;
    /

  • How to work with nested tables

    HI Everybody,
    I have a relational table one of whose columns is an object and another column is a collection stored as a nested table. I would like to set up a user interface ADF Rich Client, where I consider the parent table as Master and the nested table as Detail. If I build a READONLY master and detail view with a view link based on the primary key of the parent table, it works fine. However, when I try to generate entities from the views, the detail view object disappears from JDeveloper. Otherwise, when I try to make business components from tables, the nested table is not listed. Do anyone know a solution?
    Please help!
    Here is the view creation script with table structures:
    create or replace view dp_master_view as
    select p.dept_no,p.dept_name, p.dept_mgr.idno mgr_idno, p.dept_mgr.name mgr_name,p.dept_mgr.phone mgr_phone from department_persons p
    create or replace view dp_detail_view as
    select p.dept_no,e.* from department_persons p,table(p.dept_emps) (+) e
    SQL> desc department_persons
    Name Null? Type
    DEPT_NO NOT NULL NUMBER
    DEPT_NAME CHAR(20)
    DEPT_MGR PERSON_TYP
    DEPT_EMPS PEOPLE_TYP
    SQL> desc person_typ
    Name Null? Type
    IDNO NUMBER
    NAME VARCHAR2(30)
    PHONE VARCHAR2(20)
    Thanks, regards
    Miklos HERBOLY

    HI Everybody,
    I have a relational table one of whose columns is an object and another column is a collection stored as a nested table. I would like to set up a user interface ADF Rich Client, where I consider the parent table as Master and the nested table as Detail. If I build a READONLY master and detail view with a view link based on the primary key of the parent table, it works fine. However, when I try to generate entities from the views, the detail view object disappears from JDeveloper. Otherwise, when I try to make business components from tables, the nested table is not listed. Do anyone know a solution?
    Please help!
    Here is the view creation script with table structures:
    create or replace view dp_master_view as
    select p.dept_no,p.dept_name, p.dept_mgr.idno mgr_idno, p.dept_mgr.name mgr_name,p.dept_mgr.phone mgr_phone from department_persons p
    create or replace view dp_detail_view as
    select p.dept_no,e.* from department_persons p,table(p.dept_emps) (+) e
    SQL> desc department_persons
    Name Null? Type
    DEPT_NO NOT NULL NUMBER
    DEPT_NAME CHAR(20)
    DEPT_MGR PERSON_TYP
    DEPT_EMPS PEOPLE_TYP
    SQL> desc person_typ
    Name Null? Type
    IDNO NUMBER
    NAME VARCHAR2(30)
    PHONE VARCHAR2(20)
    Thanks, regards
    Miklos HERBOLY

  • How to create a nested table

    i want the syntax that by i can create a table in a cell of another table and how to select data from the parent table

    http://www.psoug.org/reference/nested_tab.html

  • Need help :: how to search in nested table/varray data type

    I have the following structure...
    CREATE TYPE lang_con AS VARRAY(15) OF VARCHAR2(50);
    CREATE TYPE rel_con AS VARRAY(15) OF VARCHAR2(50);
    CREATE TABLE Country_n(
    "NAME" VARCHAR2(40 BYTE) CONSTRAINT "COUNTRY_NAME_NOTNULL_N" NOT NULL ENABLE,
    "CODE" CHAR(2 BYTE),
    "CAPITAL" VARCHAR2(40 BYTE),
    "PROVINCE" VARCHAR2(40 BYTE),
    "POPULATION" NUMBER,
    "AREA" NUMBER,
    "LANGUAGES" lang_con,
    "RELIGIONS" rel_con
    after inserting data from 3 different table (country, language, religion) the table looks like this....
    Cyprus cy Nicosia Government controlled area 775927 9250 VARCHAR(English,Greek,Turkish) VARCHAR(Greek Orthodox,Muslim)
    Czech Republic cz Prague Prague 10246178 78866 VARCHAR(Czech) VARCHAR(Orthodox,Protestant,Roman Catholic)
    Germany de Berlin Berlin 82424609 357021 VARCHAR(German) VARCHAR(Muslim,Protestant,Roman Catholic)
    Djibouti dj Jibuti Jibuti 466900 23000 VARCHAR(Afar,Arabic,French,Somali) VARCHAR(Christian,Muslim)
    Denmark dk Copenhagen Frederiksberg Kommune 5413392 43094 VARCHAR(Danish,Faroese,German,Greenlandic) VARCHAR(Evangelical Lutheran,Muslim)
    now I want to get the countries in which german language is being spoken. Actually I need to know how to search in this custom data type of mine....I also need to perform other operation further so really need to know how can I search in this custom data type...
    when I execute the following query....
    select * from country_n cn where cn.languages like '%German%' order by name
    I got the following error....
    Error starting at line 1 in command:
    select * from country_n cn where cn.languages like '%German%' order by name
    Error at Command Line:1 Column:33
    Error report:
    SQL Error: ORA-00932: inconsistent datatypes: expected NUMBER got AHMADM.LANG_CON
    00932. 00000 - "inconsistent datatypes: expected %s got %s"
    *Cause:   
    *Action:
    let me know please...looking forward to your replies....
    Thanks,

    Hi,
    Try this:
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> SELECT t1.*
      2    FROM country_n t1,
      3         TABLE(t1.languages) t2
      4   WHERE column_value LIKE '%German%';
    NAME                                     CODE CAPITAL                                  PROVINCE                                 POPULATION       AREA LANGUAGES RELIGIONS
    Germany                                  de   Berlin                                   Berlin                                     82424609     357021 <Object>  <Object>
    SQL> Regards,

  • How to type cast PL/SQL table to REF cursor?

    any one knows how to CAST PL/SQl table to Ref cursor?
    eg
    procedure some_name(r_out out sys_refcurosr)
    IS
    type t is table of tab%ROWTYPE;
    my_type t;
    begin
    select * bulk collect into my_type from tab;
    r_out := my_type; -- need help here..
    end;
    it's 10g

    ref cursor is pointer to result set. You can not cast to PL/SQL table.
    1 create or replace procedure some_name(r_out out sys_refcursor)
    2 IS
    3 begin
    4 OPEN r_out for select * from emp;
    5* end;
    SQL> /
    Procedure created.
    SQL> var mycursor refcursor;
    SQL> exec some_name(:mycursor);
    PL/SQL procedure successfully completed.
    SQL> set linesize 2000
    SQL> print :mycursor;
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7369 SMITH CLERK 7902 12/17/80 00:00:00 800 20
    7499 ALLEN SALESMAN 7698 02/20/81 00:00:00 1600 300 30
    7521 WARD SALESMAN 7698 02/22/81 00:00:00 1250 500 30
    7566 JONES MANAGER 7839 04/02/81 00:00:00 2975 20
    7654 MARTIN SALESMAN 7698 09/28/81 00:00:00 1250 1400 30
    7698 BLAKE MANAGER 7839 05/01/81 00:00:00 2850 30
    7782 CLARK MANAGER 7839 06/09/81 00:00:00 2450 10
    7788 SCOTT ANALYST 7566 04/19/87 00:00:00 3000 20
    7839 KING PRESIDENT 11/17/81 00:00:00 5000 10
    7844 TURNER SALESMAN 7698 09/08/81 00:00:00 1500 0 30
    7876 ADAMS CLERK 7788 05/23/87 00:00:00 1100 20
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7900 JAMES CLERK 7698 12/03/81 00:00:00 950 30
    7902 FORD ANALYST 7566 12/03/81 00:00:00 3000 20
    7934 MILLER CLERK 7782 01/23/82 00:00:00 1300 10
    14 rows selected.

  • How to update nested table records ??

    Hi, I am just starting to write anything in PL/SQL and having some difficulties with basic syntax. Thanks for any help in advance.
    My problem is how to update collection (nested table of objects) with SQL statement. My nested table is not a column of regular table.
    Example:
    CREATE OR REPLACE TYPE tmpRec AS OBJECT(
    Col1 INT,
    Col2 INT
    CREATE OR REPLACE TYPE tmpTable IS TABLE OF tmpRec;
    DECLARE v tmpTable :=
    tmpMBATable(
    tmpRec(1,1),
    tmpRec(2,2),
    tmpRec(3,3),
    BEGIN
    --UPDATE TABLE(CAST(v AS tmpTable)) T SET T.Col2 = 1 WHERE T.Col1 =1;
    --UPDATE TABLE(v) T SET T.Col2 = 12 WHERE T.Col1 =1;
    --UPDATE (SELECT * FROM TABLE(v) )T SET T.Col2 = 12 WHERE T.Col =1;
    END;
    I am getting either
    PL/SQL: ORA-22841: DML is not allowed on PL/SQL Collections
    OR
    PL/SQL: ORA-00903 Bad table name.
    I found there is no problem when collection is a column of DB table (UPDATE TABLE(select collection_column from table) T SET T.Col2 = 12 WHERE T.Col1 =1;) but i want it to be just a collection without storing it in DB, is it possible ?
    Please help.

    898539 wrote:
    Thanks, for fast answer but my problem is more complex, maybe you can show me some workaround i try to use collection but maybe i should do something else...A complex problem does not mean a complex solution. In fact, complex problems should ideally be solved by breaking the complexity down into simpler components and then solving each of these in turn.
    As far as nested tables go? An interesting feature. But one that I will need a lot of convincing and justification for to consider for a production system. There are some major limitations with using nested tables. And these do not exist when using the simpler form of a standard relational child table instead.
    I am migrating from Sybase Adaptive Server Enterprise and searching for sollution for something we used temporary tables for so far.Temporary tables in Sybase are typically used to prevent concurrency issues (readers and writers blocking one another). Thus make a temp copy of the data and do not prevent concurrent access to the source data itself.
    These reasons simply do not exist in Oracle. In most cases, using temporary tables in Oracle simply because that is how it was implemented in Sybase, would be fundamentally flawed.
    Oracle is not Sybase. It does a very poor imitation of Sybase.
    I need a collection that can store some data and I need to be able to use it as a table so I can join to it via SQL query or call some DML on it.Why do you need a collection? The best place for data in Oracle is inside a table. Not inside a collection - especially not if that collection resides in PGA memory in the PL/SQL engine.
    In my store procedure I am updating, deleteing and inserting some data to it depends on context.What context? Oracle supports context namespaces - often used for virtual private database (VPDB) implementations. If you are referring to scope instead - there are a number of ways that Oracle supports scope too.
    The bottom line is that you should not approach this problem with "+how do I convert this Sybase method into an Oracle method+". Instead you need to look at the business requirement that the Sybase method addresses and then determine how best to address that requirement using Oracle.

  • NESTED Tables for Sub-types when creating table for Super-type

    If I create the following types, as an example:
    Person with subtypes: Employee and Customer
    Appointment
    CREATE OR REPLACE TYPE Person_OT AS OBJECT (
    person#                         NUMBER,
    personSurname                    VARCHAR2(50),
    personForenames               VARCHAR2(50),
    personDateOfBirth               DATE,
    personAddress                    Address_OT,
    ) NOT FINAL ;
    CREATE OR REPLACE TYPE Employee UNDER Person_OT (
    empSalary               NUMBER,
    empNoSales          NUMBER,
    makes               Appointment_List_OT
    ) FINAL ;
    CREATE OR REPLACE TYPE Appointment_OT AS OBJECT (
    some attributes
    CREATE OR REPLACE TYPE Appointment_List_OT AS TABLE OF REF Appointment_OT ;
    When creating the table to hold objects of Person type, how can the requisite nested table for representing 'makes' be declared? The below approach is not correct, however the table will not compile without naming the nested tables.
    CREATE TABLE Person_TBL OF Person_OT (
    Person#     PRIMARY KEY)
    NESTED TABLE makes STORE AS Appointment_List_NTBL;
    Advice very much appreciated!

    CREATE TABLE Person_TBL OF Person_OT(
    Person# PRIMARY KEY)
    NESTED TABLE TREAT(SYS_NC_ROWINFO$ AS EMPLOYEE).MAKES STORE AS Appointment_List_NTBL
    Table created.
    SQL> select * from user_nested_tables
      2  /
    TABLE_NAME                     TABLE_TYPE_OWNER
    TABLE_TYPE_NAME                PARENT_TABLE_NAME
    PARENT_TABLE_COLUMN
    STORAGE_SPEC                   RETURN_TYPE          ELEMENT_SUBSTITUTABLE
    APPOINTMENT_LIST_NTBL          SCOTT
    APPOINTMENT_LIST_OT            PERSON_TBL
    TREAT(SYS_NC_ROWINFO$ AS "SCOTT"."EMPLOYEE")."MAKES"
                           DEFAULT                VALUE                         N
    SQL>  SY.

  • Fill datagridview with Nested Table Object Type ???

    Hello everybody, please you help me resolve my problem?
    I follow this example: *(A Sample Application using Object-Relational features)* http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10799/adobjxmp.htm
    And this tutorial: *(Using Oracle User-Defined Types with .NET and Visual Studio)* http://www.oracle.com/technology/obe/hol08/dotnet/udt/udt_otn.htm
    Now I have 3 Object Table: Stock, Customer and Purchase Order. With the tutorial it's OK to show the data of Stock and Customer Table [there is no nested table in], but I can't do this with table Purchase Order, the tutorial don't show how to work with Nested Table type [Missing or something ?]
    When I try to display the data of table Purchase Order, I get the error:
    typeName='LINEITEMLIST_NTABTYP'' is not specified or is invalid*
    Follow the tutorial, I generate custom class for this UDT and get another error:
    this.STOCK_REF = ((object)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "STOCK_REF")));*
    Argument Exception Unhandle: Object attribute is not mapped to a custom type member.*
    Can You show me how to do this ? Show the data of the Nested Table in Visual Studio, do I have something wrong ??? Thanks and Best Regards.

    I think you need to go through the tutorial more carefully. I think you are missing steps.
    You are using a REF. Are you creating an object table for the objects to be stored in? Are you dereferencing the REF? This is covered by the Oracle by Example tutorial.
    http://www.oracle.com/technology/obe/hol08/dotnet/udt/udt_otn.htm#t11
    When you receive the nested table, it will be inside a .NET class. You can create this class by using the Create Custom Class menu item on the nested table type in server explorer.
    This class will contain a ToString method and a ToXML method.
    The question is, where are you attempting to display the data from this nested table? In a grid?
    Does it make sense to display a nested table inside one cell of a grid? No. You would need to construct a special UI that will show the
    nested table. Maybe the user clicks on the cell on the grid, which opens a new grid that displays the data. Or maybe there is a second grid on the form that always shows the nested table for the row that the first grid currently has selected.
    I realize I am not providing you the code... but it sounds like you need to design a more sohisticated UI than what the tutorial is using -- one that can handle displaying one additional table per row.

  • Open a cursor containing a nested table?

    I have created a table with several nested tables by following the examples in: http://otn.oracle.com/docs/products/oracle8/doc_index.htm
    I am now trying to query one of these nested tables using the techniques that are described.
    The two techniques are (page 31 of above reference):
    (1) "Flattened" query.
    (2) Nested cursor
    Both of these techniques work by simple SQL queries in SQl*Plus.
    However, I get compilation errors when using identical queries when trying to open and return a cursor in a stored procedure.
    Can you please help? Is this supported in 8.1.7?
    Is there a better way to query and return data using OO4O to a windows client program?
    If necessary, I would be glad to provide code samples.
    Thank you,
    Casey Cummings

    Here is a copy of my test code for the question that I posted. Any help on how I can get nested table data back to a windows client would be greatly apreciated.
    Thank you.
    Casey Cummings
    --DDL.
    --Original table.
    CREATE TABLE MY_TABLE(
    MY_KEY INTEGER,
    MY_DATA VARCHAR2(2000));
    --Basic Object types.
    CREATE TYPE MY_NUMERIC_OBJTYP AS OBJECT(
    SEQUENCE INTEGER,
    DATUM NUMBER);
    CREATE TYPE MY_TEXT_OBJTYP AS OBJECT(
    SEQUENCE INTEGER,
    DATUM VARCHAR2(255));
    --Table type. Table of basic objects.
    CREATE TYPE MY_NUMERIC_TABTYP AS TABLE OF MY_NUMERIC_OBJTYP;
    CREATE TYPE MY_TEXT_TABTYP AS TABLE OF MY_TEXT_OBJTYP;
    --Add nested tables to original table.
    ALTER TABLE MY_TABLE ADD(
    MY_NUMERIC_NTAB MY_NUMERIC_TABTYP)
    NESTED TABLE MY_NUMERIC_NTAB STORE AS MY_NUMERIC_TABLE;
    ALTER TABLE MY_TABLE ADD(
    MY_TEXT_NTAB MY_TEXT_TABTYP)
    NESTED TABLE MY_TEXT_NTAB STORE AS MY_TEXT_TABLE;
    --Insert test data in the main, unnested table.
    INSERT INTO MY_TABLE(
    MY_KEY, MY_DATA
    )VALUES(
    1001, 'RECORD-1001');
    COMMIT;
    --Create the actual nested tables.
    UPDATE MY_TABLE SET
    MY_NUMERIC_NTAB = MY_NUMERIC_TABTYP();
    UPDATE MY_TABLE SET
    MY_TEXT_NTAB = MY_TEXT_TABTYP();
    COMMIT;
    --Insert test data into the nested tables.
    INSERT INTO TABLE(
    SELECT X.MY_NUMERIC_NTAB
    FROM MY_TABLE X
    WHERE MY_KEY = 1001
    )VALUES(
    1,901);
    INSERT INTO TABLE(
    SELECT X.MY_NUMERIC_NTAB
    FROM MY_TABLE X
    WHERE MY_KEY = 1001
    )VALUES(
    2,902);
    INSERT INTO TABLE(
    SELECT X.MY_NUMERIC_NTAB
    FROM MY_TABLE X
    WHERE MY_KEY = 1001
    )VALUES(
    3,903);
    INSERT INTO TABLE(
    SELECT X.MY_TEXT_NTAB
    FROM MY_TABLE X
    WHERE MY_KEY = 1001
    )VALUES(
    1,'ONE');
    COMMIT;
    BOTH OF THESE QUERYS WORK WHEN ENTERED IN SQL*PLUS.
    --"FLATTENED" QUERY
    SELECT X.MY_DATA, N.SEQUENCE, N.DATUM, T.SEQUENCE, T.DATUM
    FROM
    MY_TABLE X,
    TABLE(X.MY_NUMERIC_NTAB) N,
    TABLE(X.MY_TEXT_NTAB) T
    WHERE X.MY_KEY = 1001;
    --"CURSOR" QUERY
    SELECT X.MY_DATA,
    CURSOR(
    SELECT *
    FROM TABLE (MY_NUMERIC_NTAB) ),
    CURSOR(
    SELECT *
    FROM TABLE (MY_TEXT_NTAB) )
    FROM MY_TABLE X
    WHERE X.MY_KEY = 1001;
    CREATE OR REPLACE PACKAGE MANAGE_TEST AS
    TYPE THE_CURSOR IS REF CURSOR;
    PROCEDURE QUERY_TEST(
    MY_CURSOR IN OUT THE_CURSOR
    END;
    CREATE OR REPLACE PACKAGE BODY MANAGE_TEST AS
    PROCEDURE QUERY_TEST(
    MY_CURSOR IN OUT THE_CURSOR
    AS
    BEGIN
    OPEN MY_CURSOR FOR
    --"FLATTENED" QUERY
    SELECT X.MY_DATA, N.SEQUENCE, N.DATUM, T.SEQUENCE, T.DATUM
    FROM
    MY_TABLE X,
    TABLE(X.MY_NUMERIC_NTAB) N,
    TABLE(X.MY_TEXT_NTAB) T
    WHERE X.MY_KEY = 1001;
    END;
    END;
    *****************Errors:
    LINE/COL ERROR
    8/5 PL/SQL: SQL Statement ignored
    11/13 PLS-00201: identifier 'X.MY_NUMERIC_NTAB' must be declared
    CREATE OR REPLACE PACKAGE BODY MANAGE_TEST AS
    PROCEDURE QUERY_TEST(
    MY_CURSOR IN OUT THE_CURSOR
    AS
    BEGIN
    OPEN MY_CURSOR FOR
    --"CURSOR" QUERY
    SELECT X.MY_DATA,
    CURSOR(
    SELECT *
    FROM TABLE (MY_NUMERIC_NTAB) ),
    CURSOR(
    SELECT *
    FROM TABLE (MY_TEXT_NTAB) )
    FROM MY_TABLE X
    WHERE X.MY_KEY = 1001;
    END;
    END;
    *****************Errors:
    LINE/COL ERROR
    11/11 PLS-00103: Encountered the symbol "SELECT" when expecting one of
    the following:
    ( ) - + mod not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable>
    table avg count current exists max min prior sql stddev sum
    variance execute multiset the both leading trailing forall
    year month DAY_ HOUR_ MINUTE_ second TIMEZONE_HOUR_
    TIMEZONE_MINUTE_ time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL stri
    12/41 PLS-00103: Encountered the symbol "," when expecting one of the
    following:
    ; return returning and or
    null

  • Nested Tables and Advanced Queues- Please Help.

    How do i work with NestedTable type and Advanced Queue.
    I have done the following
    I have Oracle 8.1.7 enterprise edition.
    create type myType as TABLE OF varchar(32);
    create type myObject as OBJECT (
    id int,
    myt myType);
    DECLARE
    BEGIN
    dbms_aqadm.create_queue_table(
    queue_table => 'my_queue_table',
    multiple_consumers => TRUE,
    queue_payload_type => 'myObject',
    compatible => '8.1.3'
    END;
    The Nested Table and Object are created successfully.
    but the queue is not created.
    I get the following message.
    DECLARE
    ERROR at line 1:
    ORA-22913: must specify table name for nested table column or
    attribute
    ORA-06512: at "SYS.DBMS_AQADM_SYS", line 2012
    ORA-06512: at "SYS.DBMS_AQADM", line 55
    ORA-06512: at line 3
    I know how to specify the nested table storage clause for
    create table statement, but there is no provision for
    it in the create_queue_table procedure.
    Any help will be greately appriciated.
    i have already created and tested aqs with simple data types,
    also i have created simple tables with nested table type
    elements.
    but the combo of Nested tables and AQ is not working.
    thanks in advance.

    Hi Francois. Thank you very much for your reply, but it seems that i still get errors. So let me tell what i have done.
    As you suggested me: i have done a block based on a sub-query for the nested-table:
    'select courses from department where name= :department.name'.
    In the master block(department) i have the when-new-record-instance trigger:
    Declare
    LC$Req varchar2(256);
    Begin
    LC$Req := '(select ns.courses from table
    ( select courses from department where name = ''' || :DEPARTMENT.name || ''' ) ns )';
    Go_block('block11');
    Clear_Block ;
    Set_Block_Property( 'block11', QUERY_DATA_SOURCE_NAME, LC$Req ) ;
    Execute_query ;
    End ;
    Now the errors i receive, this time in the runtime mode are:
    - FRM-41380: Cannot set the blocks query data source
    -FRM-41003: This function cannot be performed here.
    Since it seems that you know how to work with the nested table i would really appreaciate your help. I am new in the nested table and if you could give an ex with my tables it would be great.
    Thank you in advance.

  • Multilevel nested table

    Does anyone know how to create a table with a column of a nested-table type with a nested-table element type?
    I created a table with a column of a single-level nested-table type as follows:
    create type MTYPE as object(
    I NUMBER,
    member function GETI return NUMBER,
    member procedure SETI(V NUMBER));
    create type TABTYPE as table of MTYPE;
    create table TABTABLE(C1 TABTYPE)
    nested table C1 store as TABTABLEC1;
    But I could not create a table with a column of the following type:
    create type TABTYPE2 as table of TABTYPE;
    Is it not possible to do so? I do not know how to write the "nested table" and the "store as" parts in the "create table" statement.

    Hi,
    this is the example:
    SQL> CREATE TYPE objtype AS OBJECT (ID NUMBER);
    2 /
    Type created.
    SQL> CREATE TYPE objtype_tab AS TABLE OF objtype;
    2 /
    Type created.
    SQL> CREATE TYPE objtype_cover AS OBJECT (nest objtype_tab)
    2 /
    Type created.
    SQL> CREATE TYPE objtype_cover_tab AS TABLE OF objtype_cover
    2 /
    Type created.
    SQL> CREATE TABLE obj_nest_table (
    2 name VARCHAR2(10),
    3 objs objtype_cover_tab)
    4 NESTED TABLE objs STORE AS objs_tab
    5 (NESTED TABLE nest STORE AS nest_tab)
    6 /
    SQL> insert into obj_nest_table values('A', objtype_cover_tab( objtype_cover (objtype_tab ( objtype(
    200)))));
    1 row created.
    Rgds.

  • How to insert reference of object in nested table

    hi , i have a problem with nested table :
    CREATE OR REPLACE TYPE ITEM AS OBJECT
    ITEM_ID NUMBER,
    ITEM_DES VARCHAR2(4000),
    PRODUCT_NO VARCHAR2(15),
    PRODUCT_DES VARCHAR2(4000)
    CREATE TABLE ITEMS OF ITEM
    CONSTRAINT ITEM_PK PRIMARY KEY (ITEM_ID)
    CREATE OR REPLACE TYPE BOM AS OBJECT
    BOM_ID NUMBER,
    ITEM_ID NUMBER,
    BOM_PARENT_ID number
    create or replace type boms as table of ref bom;
    create table bom_table
    bom_ids bom,bom_member boms
    ) nested table bom_member store as bom_childs;
    insert into bom_table (bom(1,1,null),null);
    insert into bom_table (bom(2,1,1),boms(select ref(t) from bom_table t where t.bom_id=1))
    show error.
    how i can insert in nested table reference of object
    thanks

    your table "bom_table" is not an object table or view, and thus you can't create object references to it's rows. you'll need to create an object table or view of "bom" objects, with a corresponding object identifier, and then reference that table/view in your subquery instead.
    Gerard

Maybe you are looking for