Reg: Querying Nested table.

Hi,
I am facing a problem with querying the Nested table.
I have created a type
CREATE OR REPLACE TYPE TY_BOOKS OBJECT(           VC_BOOK_NAME VARCHAR2(64)          );
CREATE OR REPLACE TYPE NT_TY_BOOKS AS TABLE OF TY_BOOKS;
I have used this nested table in a table Student.
CREATE TABLE STUDENT
( SID NUMBER(10),
CL_NT_BOOKS NT_TY_BOOKS)
NESTED TABLE CL_NT_BOOKS STORE AS CL_NT_BOOKS_TAB;
The problem is one student can have more than one book. So if I need to select the students who have 'Science' books, i wrote this query.
SELECT S.SID,B.VC_BOOK_NAME FROM STUDENT S, TABLE(CL_NT_BOOKS) B WHERE B.VC_BOOK_NAME='Science';
suppose in the table
SID BOOK_NAME
1000          CL_NT_BOOKS('Science')
1001          CL_NT_BOOKS('Maths'),CL_NT_BOOKS('Science')
This query will return only those student-ids who have only "Science" book not those student-ids who have "Maths" & "Science" books.
RESULT
1000          Science
but not 1001....
Please can any one send me the select query which can select iteratively for books names which contains more than one value.

Hmm, mysterious. It works for me on my 9.2.0.6 dB...
SQL> CREATE OR REPLACE TYPE TY_BOOKS AS  OBJECT( VC_BOOK_NAME VARCHAR2(64) );
  2  /
Type created.
SQL> CREATE OR REPLACE TYPE NT_TY_BOOKS AS TABLE OF TY_BOOKS;
  2  /
Type created.
SQL> CREATE TABLE STUDENT
  2  ( SID NUMBER(10),
  3  CL_NT_BOOKS NT_TY_BOOKS)
  4  NESTED TABLE CL_NT_BOOKS STORE AS CL_NT_BOOKS_TAB;
Table created.
SQL> INSERT INTO student VALUES (1000, NT_TY_BOOKS(TY_BOOKS('Science')))
  2  /
1 row created.
SQL> INSERT INTO student VALUES (1001, NT_TY_BOOKS(TY_BOOKS('Science'),TY_BOOKS('Maths')))
  2  /
1 row created.
SQL>
SQL> SELECT S.SID,B.VC_BOOK_NAME FROM STUDENT S, TABLE(CL_NT_BOOKS) B
  2  WHERE B.VC_BOOK_NAME='Science'
  3  /
       SID VC_BOOK_NAME
      1000 Science
      1001 Science
SQL> What I suggest is most likely to have happened is that you have added a space or some other non-printing cahracter into the book name when you inserted row 1001. If this is not the case then you'll have to do it again in SQL*Plus, cut teh output and paste it here, so we can see what's going on.
Cheers, APC

Similar Messages

  • Querying Nested Table......

    Hi,
    I am new to this nested table topic, I am facing problem in querying nested table. Actually i had created a table which consists of details regarding Applications and the platforms. As an application can run on more than one platform i had created a nested table for platform.
    CREATE OR REPLACE TYPE TY_PLATFORM AS OBJECT
    (           VC_PLATFORM VARCHAR2(64)          );
    CREATE OR REPLACE TYPE NT_TY_PLATFORM AS TABLE OF TY_PLATFORM;
    I am using this nested table in the main table application:
    CREATE TABLE T_APPLICATION
    ( N_APPLICATION_ID NUMBER(32,6),
         VC_APPLICATION_NAME VARCHAR2(160),
    CL_NT_PLATFORM NT_TY_PLATFORM )
    NESTED TABLE CL_NT_PLATFORM STORE AS CL_NT_PLATFORM_TAB
    The table contains the data like this(Just for example):
    N_APPLICATION_ID VC_APPLICATION_NAME PLATFORM
    1 ABC Unix, Windows
    2 DEF Unix, MVS
    3 GHI Unix, Windows
    4 JKL Unix, Windows, MVS
    I have created the scripts like this...
    INSERT INTO T_APPLICATION(N_APPLICATION_ID, VC_APPLICATION_NAME) VALUES(1,'ABC');
    Like that for all applications...
    UPDATE T_APPLICATION SET CL_NT_PLATFORM=NT_TY_PLATFORM(TY_PLATFORM('Unix'),TY_PLATFORM('Windows')) WHERE N_ACCESS_NUMBER=1;
    Like that for all applications.....
    After creation i had queried
    SQL> select t.n_application_id from t_application t,table(cl_nt_platform)p
    2 where p.vc_platform='Unix' and p.vc_platform='Windows' and p.vc_platform!='MVS';
    no rows selected
    Actually i want the application list which run on unix and windows platform but not MVS
    It want the result like this:
    T.N_APPLICATION_ID
    1
    2
    but it is returning no rows selected.......
    Please help me......
    Thanks in advance.....

    Wrong forum my friend. This forum is for XML DB related issues, and while we use nested tables, we never have to worry about those nasty objects that were generated by XML Schema registration :)...
    I think you need...
    Objects

  • Query Nested table (collection)

    I try to query on a nested table (collection).
    How ever, I get a 600 error.
    Is there any way to reuse the result of query in the store procedure?
    SQL> DECLARE
    2 TYPE T_PER_ID IS TABLE OF PERIOD.PER_ID%TYPE;
    3 V_EXP_PER_ID T_PER_ID;
    4 V_EXP_PER_ID2 T_PER_ID;
    5 BEGIN
    6 SELECT PER_ID BULK COLLECT INTO V_EXP_PER_ID FROM PERIOD;
    7 SELECT * BULK COLLECT INTO V_EXP_PER_ID2 FROM TABLE(V_EXP_PER_ID);
    8 END;
    9 /
    DECLARE
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL
    execution], [], [], [], [], [], []
    ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [],
    ORA-06553: PLS-801: internal error [0]

    Oracle Version 8.1.6

  • Querying Nested Tables from BO

    Hi,
    I have a nested table [VA_GT_HC_ASIA_SGP ] in Oracle. The Inner Object in the nested table has got 4 columns, which has to be displayed in the WebI Report.
    Hece I created the table as derived table in Universe by the below query.
    select a.COL1, b.COL2, b.COL3, b.COL4, b.COL5 from VA_GT_HC_ASIA_SGP a, Table(a.OB_GT_HC_MAINT_INFO) b
    But performance is very slow. Please advice if there exists a better way to do this.
    Best Regards,
    Anu

    The Query is:-SELECT A.ID, A.NAME, A.COMB, B.C1,B.C2, B.C3  FROM NT_KFD_RFT_TEST_DATE A, TABLE(OB_KFD_RFT_DATA) B
    Nested Table structure Example:-
    ID       NAME    COMB   OB_KFD_RFT_DATA
    01      TEST     ALL    
    The inner table (OB_KFD_RFT_DATA) structure is
    C1      C2        C3
    23.5   56.7   78.9
    00.9   76.9   53.3
    12.4   33.4   23.2
    Here outer record is 01 TEST ALL, and inner record is the 3 row decimal numbers.
    In Universe, I need to create Objects from C1,       C2,      C3 columns.
    Currently i'm doing it with derived table (by running above query). Is there any other option to do it?
    Thanks,
    Anu

  • Querying Nested Tables with Multiple other Tables

    I am trying to query columns from a table and it's nested table and do a join to another table.
    SELECT IM.*,
    IMP.PROGRAM_ID,
    S.STAGE_NAME
    FROM TB_ITEM_MASTER IM , TABLE(TB_ITEM_MASTER.PROGRAMS) IMP, TB_STAGE S
    WHERE S.STAGE_ID = IM.STAGE_ID
    AND IM.PROGRAM_ID IN(1,2);
    When running this query I receive the error:
    ORA-00904:"TB_ITEM_MASTER"."PROGRAMS": Invalid Identifier
    I actually copied this query straight from an Oracle Documentation, just replaced my table names with theirs. This query will almost be like a template to me as the program_id field in the Nested table is very cruicial to me. I will joining many tables to TB_ITEM_MASTER and using the where clause against program_id. What's the problem here?
    Please advise.
    ps. Did I mention how much I hate working with this Nested table stuff:(

    You must use the alias name, not the table name.
    SQL> create type employee_obj as object (empno number) ;
      2  /
    Type created.
    SQL> create type employees_nt is table of employee_obj ;
      2  /
    Type created.
    SQL> create table departments (deptno number(2), dname varchar2(20), employees employees_nt)
      2  nested table employees store as employees_table
      3  /
    Table created.
    SQL> insert into departments values (1, 'DEPT #1', employees_nt(employee_obj(2), employee_obj(3))) ;
    1 row created.
    SQL> insert into departments values (22, 'DEPT #2', employees_nt(employee_obj(22), employee_obj(33))) ;
    1 row created.
    SQL>
    SQL> SELECT IM.*,
      2  IMP.empno
      3  FROM departments IM , TABLE(IM.employees) IMP
      4  WHERE IM.deptno IN(1,2);
        DEPTNO DNAME
    EMPLOYEES(EMPNO)
         EMPNO
             1 DEPT #1
    EMPLOYEES_NT(EMPLOYEE_OBJ(2), EMPLOYEE_OBJ(3))
             2
             1 DEPT #1
    EMPLOYEES_NT(EMPLOYEE_OBJ(2), EMPLOYEE_OBJ(3))
             3
    2 rows selected.
    SQL>

  • Reg:varray & nested table.

    Dear Friends,
    How varray & Nested table working internally in oracle.?
    When & Why to use varray & nested table.?
    Which is the faster from both of them.?
    Thanks.

    Hmm, mysterious. It works for me on my 9.2.0.6 dB...
    SQL> CREATE OR REPLACE TYPE TY_BOOKS AS  OBJECT( VC_BOOK_NAME VARCHAR2(64) );
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE NT_TY_BOOKS AS TABLE OF TY_BOOKS;
      2  /
    Type created.
    SQL> CREATE TABLE STUDENT
      2  ( SID NUMBER(10),
      3  CL_NT_BOOKS NT_TY_BOOKS)
      4  NESTED TABLE CL_NT_BOOKS STORE AS CL_NT_BOOKS_TAB;
    Table created.
    SQL> INSERT INTO student VALUES (1000, NT_TY_BOOKS(TY_BOOKS('Science')))
      2  /
    1 row created.
    SQL> INSERT INTO student VALUES (1001, NT_TY_BOOKS(TY_BOOKS('Science'),TY_BOOKS('Maths')))
      2  /
    1 row created.
    SQL>
    SQL> SELECT S.SID,B.VC_BOOK_NAME FROM STUDENT S, TABLE(CL_NT_BOOKS) B
      2  WHERE B.VC_BOOK_NAME='Science'
      3  /
           SID VC_BOOK_NAME
          1000 Science
          1001 Science
    SQL> What I suggest is most likely to have happened is that you have added a space or some other non-printing cahracter into the book name when you inserted row 1001. If this is not the case then you'll have to do it again in SQL*Plus, cut teh output and paste it here, so we can see what's going on.
    Cheers, APC

  • Query nested table?

    Let's say I have an object type "pair" with elements "name" and "value". I create a nested table type "pairtable" of type "pair". Then I create a view, "view", that has a column "nametable". The values in "nametable" are the result of a function that takes the value in the first column of the view, "id", and builds a nested table of type "pairtable" with the "names" and "values" associated with "id" that are stored in other tables. Clear as mud, yes?
    If I type this into SQL+
    select * from view where id = 100
    I get
    id col2 col3 col4 nametable
    100 A B C pairtable(pair(aname, avalue)),pairtable(pair(bname, bvalue)),...
    What I want is a cursor that contains only the "names" and "values" from a select number of "id"s.
    What is the syntax?
    Database is 8i, client is 9.2.
    (p.s. Eventually I will want to call these name value pairs from .NET as a REF Cursor. For now I will settle for something that works in PL/SQL)

    Ross,
    OLEDB does not support object types or nested table. This restriction is limited by the Microsoft OLEDB specfication.
    This forum is for ODP.NET. You may want to post this question to OLEDB forum.
    Thanks
    Martha

  • REG:QUERY THE TABLE

    Hi
    I have table EMP(empid,empname,deptid) ,DEPT(depid,name) .When i query i want to fetch data eventhough depid is null in emp table.
    thx in advance

    That is what is called an outer join.
    usually a left outer join. And instead of the old school oracle syntax you should use the newer fresh Ansi style syntax.
    select *
    from emp e
    LEFT JOIN dept d on d.dept_id = e.dept_id;

  • Nested table collection in select query "in clause" taking long time

    create or replace type t_circuitids is table of varchar2(100);
    --Below anonymous block keeps on running and never ends
    DECLARE
       v_circuitid    t_circuitids;
       v_count number;
       l_circuitids   VARCHAR2 (4000)
          := 'value1,value2,value3,value4,value5';
    BEGIN
    --Below query converts comma concatinated output to list and stores in nested table collection v_circuitids
       WITH a AS
            (SELECT ',' || l_circuitids || ',' AS circuitid
               FROM DUAL)
       SELECT DISTINCT TRIM (SUBSTR (circuitid,
                                     INSTR (circuitid, ',', 1, LEVEL) + 1,
                                       INSTR (circuitid, ',', 1, LEVEL + 1)
                                     - INSTR (circuitid, ',', 1, LEVEL)
                                     - 1
                            ) cid
       BULK COLLECT INTO v_circuitid
                  FROM a
            CONNECT BY LEVEL <
                             LENGTH (circuitid)
                             - LENGTH (REPLACE (circuitid, ','));
       SELECT COUNT (1)
         INTO v_count
         FROM table
        WHERE name IN (SELECT COLUMN_VALUE
                                          FROM TABLE (v_circuitid));
    END;
    --I got the issue, query "SELECT COLUMN_VALUE FROM TABLE (v_circuitid)" which is used in above code is responsible for this.
    --Same code works fine in Development and Test environments, But in prod it keeps on running
    --I solved this issue by creating a temp table, loading all values in collection into the temp table and using that temp table in "in clause"    "
    --Can any one answer why its behaving like this when i use collection in where clause?
    --I am using Oracle 9i

    Below is the code i used
    DECLARE
       v_circuitid    t_circuitids;
       v_count number;
       l_circuitids   VARCHAR2 (4000)
          := 'value1,value2,value3,value4,value5';
    BEGIN
    --Below query converts comma concatinated output to list and stores in nested table collection v_circuitids
       WITH a AS
            (SELECT ',' || l_circuitids || ',' AS circuitid
               FROM DUAL)
       SELECT DISTINCT TRIM (SUBSTR (circuitid,
                                     INSTR (circuitid, ',', 1, LEVEL) + 1,
                                       INSTR (circuitid, ',', 1, LEVEL + 1)
                                     - INSTR (circuitid, ',', 1, LEVEL)
                                     - 1
                            ) cid
       BULK COLLECT INTO v_circuitid
                  FROM a
            CONNECT BY LEVEL <
                             LENGTH (circuitid)
                             - LENGTH (REPLACE (circuitid, ','));
       SELECT COUNT (1)
         INTO v_count
         FROM table
        WHERE name IN (SELECT COLUMN_VALUE
                                          FROM TABLE (ccard(v_circuitid)));
    END;
    And got below error
    ORA-06550: line 27, column 5:
    PL/SQL: ORA-00906: missing left parenthesis
    ORA-06550: line 24, column 4:
    PL/SQL: SQL Statement ignored

  • Nested Tables select query soooooo slow

    I know that varrays are supposed to be used for small arrays. But, we are comparing nested tables to varrays and two table joins. Nested table query is unimaginably ,unacceptably slow.
    Is there anybody else out there who experienced the same thing. Are there ways to speed up the select queries.(besides indexes)

    If you try to use nested sql statement. Please be sure to setup the index to some specific tables inside oracle
    Doing this will speed up your performance about 5 ~ 9 times original.
    [email protected]

  • Sql query, from xml to nested table

    Hello!
    I have DB table: my_table
    It has 2 fields: file_id and file_data (it's clob with xml)
    I need to write query that returns info from xml using nested table (Oracle v.9)
    The number of rows witch will return query must be equal to number of files (file_id)
    Structure of XML:
    <?xml version = "1.0" encoding = "utf-8"?>
    <head>
    <AAA v1="a" v2="b">
    <BBB p1="1" p2="2"/>
    <BBB p1="3" p2="4"/>
    </AAA>
    <AAA v1="c" v2="d">
    <BBB p1="5" p2="6"/>
    <BBB p1="7" p2="8"/>
    <BBB p1="9" p2="0"/>
    </AAA>
    </head>
    I have query, witch works! but not optimally! each CLOB scaned 3 times - I want to scan it once!
    SELECT an.file_id,
    CAST(MULTISET(SELECT extract(VALUE(val2),'//@v1').getStringVal() v1,
    extract(VALUE(val2),'//@v2').getStringVal() v2,
    CAST(MULTISET(SELECT extract(VALUE(val3),'//@p1').getStringVal() p1,
    extract(VALUE(val3),'//@p2').getStringVal() p2,
    FROM TABLE (XMLSEQUENCE(XMLTYPE(an.file_data).EXTRACT('/head/AAA/BBB[../@v1='||extract(VALUE(val2),'//@v1').getStringVal()||']'))) val3) AS T_VAL3) info
    FROM TABLE (XMLSEQUENCE(XMLTYPE(an.file_data).EXTRACT('/head/AAA'))) val2) AS T_VAL2) head
    FROM (SELECT olr.*
    FROM my_table olr,
    TABLE (XMLSEQUENCE(XMLTYPE(file_data)).EXTRACT('/head'))) val1) an
    PLEASE, help me to rewrite this query!

    I assume you're using nested objects like these to hold the result?
    create type t_val3_rec as object ( p1 number, p2 number );
    create type t_val3 as table of t_val3_rec;
    create type t_val2_rec as object ( v1 varchar2(30), v2 varchar2(30), c1 t_val3 );
    create type t_val2 as table of t_val2_rec;
    /then this query should work :
    SELECT t.file_id
         , CAST(
             MULTISET(
               SELECT extractvalue(value(x1), '/AAA/@v1')
                    , extractvalue(value(x1), '/AAA/@v2')
                    , CAST(
                        MULTISET(
                          SELECT extractvalue(value(x2), '/BBB/@p1')
                               , extractvalue(value(x2), '/BBB/@p2')
                          FROM TABLE(XMLSequence(extract(value(x1), '/AAA/BBB'))) x2
                        AS t_val3
               FROM TABLE(XMLSequence(extract(value(x), '/head/AAA'))) x1
             AS t_val2
    FROM my_table t
       , TABLE(XMLSequence(extract(xmltype(t.file_data), '/head'))) x
    ;

  • Query in Nested Table

    Hi Friends,
    My Present project requires to query a nested table for key words and display a result based on the occurence of key words
    The description of table
    Name Type Nullable Default Comments
    CID NUMBER(10)
    NT_KEYMAP NT_KEYS(NESTED TABLE)Y
    FLAG NUMBER(1) 0
    MGR_ID NUMBER(10)
    CATEGORY_ID NUMBER(10)
    NT_KEYS is a nested table of varchar2(50).
    Each key words of the card is stored in the nested table.
    Now when a user enters the key words for searching , I want to display the result depending upon the occurence of key words of a particular key word.
    Could some one help me most optimised search method of nested table.
    Thanks in advance,
    Suman

    If you're asking how to do this with the TopLink Java-based expression framework -- it's not possible. You would be best to use ad hoc SQL for this kind of query. As for what that SQL would look like, I'd check with one of the database forums.
    - Don

  • XML Query Performance on Nested Tables

    I am running an Xpath query on an XMLTYPE column extracting rows from a nested table which is two levels down from the root element:
    e.g.
    select extractValue(x.xmldata,'/rootElement/VersionNumber') VerNumber
    , etc...
    , etc.
    , extractValue(value(m),'/Member/Name/Ttl') Member_title
    , to_char(extractValue(value(e),'/Event/EventDate'),'yyyy-mm-dd') Event_Date
    , extractValue(value(e),'/Event/Type') Event_type
    from xml_table x,
    table(XMLSequence(extract(x.xmldata,'/rootElement/Member'))) m
    ,table(XMLSequence(extract(value(m),'/Member/Event'))) e
    The query is taking around 7 minutes to process 2000 XML docs and the result returns 61,000 rows.
    Statspack reports indicate that the main resource used is the LOBSEGMENT which supports the SYS_XDBPD$ column (system generated) in the Member nested table - result was over 100 million Logical Reads and Consistent Gets.
    Is there any way to influence the Schema Registration/XML Table creation to result in the XDBPD$ column being stored as a Table or VARRAY - the underlying data type for XDBPD$ is:
    XDB.XDB$RAW_LIST_T VARRAY(1000) OF RAW(2000)
    OR
    Should I spend time tuning access to the LOBSEGMENT?
    Anyone tuned this area of XDB before??
    Thanks
    Dave

    Do you need DOM Fidelity at all. DOM Fidelity is typically only needed in a document orientated application or where items like processing instructions and comments are present and need to be maintaned.
    Here are some notes from some training ppt slides that may help you decide
    Dom Fidelity requires that XML DB track document level meta data
    It creates overhead when inserting and retrieving XML due to processing as well as adding additional storage requirements. Dom Fidelity can be turned on and off at the 'Type' Level Each SQL Type corresponding to a complexType where DOM is enabled includes a System Binary attribute called SYS_XDBPD$. The SYS_XDBPD$ attribute is referred to as the Positional Descriptor (PD)
    The PD is used to manage the instance level meta data. The format of the PD is not documented The PD is stored as a (in-line) LOB.
    The PD is used to track
    Comments and Processing Instructions
    Location and Prefixes in Namespace declarations
    Empty Vs Missing Nodes
    Presence of Default Values
    Use of Substitutable elements
    Ordering of elements in all and choice models
    XMLSchemaInstance attributes
    xsi:nil, xsi:Type
    Mixed content –
    Text() nodes that are interspaced with elements
    Disabling DOM Fidelity improves performance
    Reduces storage requirements
    Reduces elapsed time for insert and retrieval operations
    DOM Fidelity is disabled on a Type by Type basis
    Use annotation xdb:maintainDOM="false“ on complexType definition
    Specifying xdb:maintainDOM="false“
    Removes the PD attribute from the SQLType.
    Causes the information managed in the PD to be discarded when shredding the XML document
    In general you can disable DOM Fidelity when
    All information is represented as simple content
    Elements with text() node children and or attribute values
    XML does not make use Mixed Text
    No Comments or Processing Instructions
    Applications do not need to differentiate between empty and missing elements
    Applications do not differentiate between default Vs missing values
    Order of elements in repeating Sequence, All and Choice models is not meaningful
    Typically Data-Centric XML does not require DOM Fidelity while Document Centric XML does. With DOM Fidelity disabled retrieved documents will still be valid per the XML Schema
    Order is preserved when repetition is specified at element or complexType level
    Use annotation xdb:maintainOrder=“false” for slight performance improvement in this case that order is not required in these cases.
    Order is not preserved when repetition is specified at the ‘model’ level, eg on a Choice, Sequence or All containing multiple child elements.
    Take the following document
    <?xml version="1.0" encoding="UTF-8"?>
    <!--Sample XML file generated by XMLSPY v2004 rel. 4 U (http://www.xmlspy.com)-->
    <dft:root xmlns:dft="domFidelityTest"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="domFidelityTest domFidelityExample">
    <?SomePI SomeValue?>
         <xxx:choice xmlns:xxx="domFidelityTest">
         <!--SomeComment-->
              <xxx:A>String</xxx:A>
              <xxx:B>String</xxx:B>
              <?Another PI SomeOtherValue?>
              <xxx:C>String</xxx:C>
              <xxx:A>String</xxx:A>
              <!--Another Comment-->
              <xxx:B>String</xxx:B>
              <xxx:C xsi:nil="true"/>
    </xxx:choice>
    </dft:root>
    With DOM Fidelity disabled it would come back as
    <?xml version="1.0" encoding="WINDOWS-1252"?>
    <!--Sample XML file generated by XMLSPY v2004 rel. 4 U (http://www.xmlspy.com)-->
    <dft:root xmlns:dft="domFidelityTest“ testAttr="NotInOriginal">
    <dft:choice>
    <dft:A>String</dft:A>
    <dft:A>String</dft:A>
    <dft:B>String</dft:B>
    <dft:B>String</dft:B>
    <dft:C>String</dft:C>
    <dft:C/>
    </dft:choice>
    </dft:root>
    In general you can disable DOM Fidelity and see reduced storage requirements and increased throughout...
    Hope this helps...

  • Please help with multiple insert query into nested table!!!!

    I am having a problem with inserting multiple references to objects into a nested table using the following query:
    INSERT INTO TABLE(SELECT Taken_by FROM courses WHERE course_number= 001)
    (SELECT REF(p) FROM persons p
    WHERE p.enroled_in = 'Computing for Business'
    The database says that p.enroled_in is an invalid identifier. I know why this is. This is because the field enroled_in is part of a subtype of person called student_type and the query above is not accounting for this properly. I would like to know the correct syntax to use so I can insert into the nested table wherever a student is enroled into the 'computing for business' course. My full schema is below:
    CREATE TYPE person_type;
    CREATE TYPE student_type;
    CREATE TYPE staff_type;
    CREATE TYPE course_type;
    CREATE TYPE module_type;
    CREATE TYPE address_type AS OBJECT
    Street VARCHAR2 (30),
    Town     VARCHAR2 (30),
    County VARCHAR2 (30),
    Postcode VARCHAR2 (9)
    CREATE TYPE person_type AS OBJECT
    Name VARCHAR2 (50),
    Address address_type,
    DOB     DATE
    ) NOT FINAL;
    CREATE TYPE staff_type UNDER person_type
    Staff_number NUMBER (2,0)
    ) FINAL;
    CREATE TYPE student_type UNDER person_type (
    Student_number NUMBER (2,0),
    Enroled_in VARCHAR2(50),
    MEMBER FUNCTION getAge RETURN NUMBER
    )NOT FINAL;
    CREATE OR REPLACE TYPE BODY student_type AS
    MEMBER FUNCTION getAge RETURN NUMBER AS
    BEGIN
    RETURN Trunc(Months_Between(Sysdate, DOB)/12);
    END getAge;
    END;
    CREATE TYPE module_type AS OBJECT
    Module_number VARCHAR2(6),
    Module_name VARCHAR2(50),
    Credit NUMBER(2,0),
    Taught_in VARCHAR2(50)
    CREATE TYPE students_tab AS TABLE OF REF person_type;
    CREATE TYPE modules_tab AS TABLE OF REF module_type;
    CREATE TYPE course_type AS OBJECT
    Course_number NUMBER (2,0),
    Course_name VARCHAR2(50),
    Dept_name VARCHAR2(50),
    Taken_by Students_tab,
    Contains Modules_tab
    CREATE TABLE modules OF module_type(
    constraint pk_modules primary key (Module_number)
    CREATE TABLE courses OF course_type(
    constraint pk_courses primary key (Course_number)
    NESTED TABLE Taken_by STORE AS students_nt,
    NESTED TABLE Contains STORE AS modules_nt;

    By the way I am using oracle 9i and trying to insert into the nested table data from a subtype (i.e student is a subtype of person)

  • Producing nested xml with querying attributes from a nested table

    How can one produce nested xml querying columns from a nested table? Looking at the object documentation, I can readily unnest the tables. Using your examples in the book, unnesting is select po.pono, ..., l.* from purchaseorder_objtab po, table (po.lineitemlist_ntab) l where l.quantity = 2;
    what if I don't want to unnest and don't want a cursor. I would like to produce nested xml.

    Gail,
    Although you can use XSU (XML-SQL Util) in 8.1.7, I would recommend that you upgrade to 9i for much better support (both in functionality and performance) of XML in the database. For example, in Oracle9i there are:
    - a new datatype - XMLType for storing and retrieving XML documents
    - DBMS_XMLGEN package and SYS_XMLGEN, SYS_XMLAGG functions for generating XML document from complex SQL queries
    - A pipelined table function to break down large XML documents into rows.
    You can check out some examples using SYS_XMLGEN and DBMS_XMLGEN for your specific needs at http://download-west.oracle.com/otndoc/oracle9i/901_doc/appdev.901/a88894/adx05xml.htm#1017141
    Regards,
    Geoff

Maybe you are looking for

  • HELP needed! HACKED NOW LOCKED OUT

    Hi all I am very new to apple and not very good with IT anyway so please be gentle with me! I bought a new mac a few months ago which my boyfriend (whom I am 38 weeks pregnant with!) talked me into and set up for me.  7 weeks ago I caught him cheatin

  • IPad and Aperture Photo Organization

    I've searched these forums but I haven't been able to find a suitable answer to my question. I recently "upgraded" from iPhoto to Aperture 3 for my digital photo library. I rearranged all of my projects in Aperture (Events in iPhoto) and I'm fairly h

  • Linking Several Project Files as one Learning Session

    I have eight large Captivate files that I want to link into one, single window, seamless learning experience. I've tried quite a few options, but I can't get any to work. In one failed attempt, I wanted to publish 8 flash files that were linked so th

  • SSDT-BI for SQL Server 2014, Command line(silent unattendant automatic) installation script/steps

    Hi, I have downloaded SSDT-BI software and looking for commandline steps,config file for this. http://www.microsoft.com/en-us/download/details.aspx?id=42313 Any one have Command line installations steps for SSDT-BI automatic(command line) installatio

  • Error when installing with pacman

    yesterday i update my arch and now i cant install anything this is the error error: giblib: key "7F2D434B9741E8AC" is unknown error: error al realizar la transacción (paquete no válido o dañado) Ocurrieron errores, no se actualizaron paquetes any ide