Hierarchical queries and referential constraints

Experts,
What is the rationale for having a referential integrity constraint on a table that has rows bound by hierarchical relationships ?? The hierarchical relationship ensures that each row is referencing another in the same table via the PRIOR clause. If I add a foreign key relationship to these columns , does it make any sense ??/
-Rekha

but you can use a hierarchical query to display constraints in a tree !
SQL> create table t1 (a number primary key);
Table created.
SQL> create table t2 (b number primary key, a number references t1(a));
Table created.
SQL> create table t3 (c number primary key, b number references t2(b));
Table created.
SQL> create table t4 (d number primary key, a number references t1(a));
Table created.
SQL> create table t5 (e number primary key, f number references t5(e));
Table created.
SQL> select sys_connect_by_path(p.table_name,':')||':'||r.table_name p
from all_constraints p
    join all_constraints r
    on (p.constraint_name = r.r_constraint_name and p.owner = r.r_owner)
where CONNECT_BY_ISLEAF = 1
connect by nocycle prior r.table_name = p.table_name
start with p.table_name not in (select r.table_name from all_constraints p join
all_constraints r on (p.constraint_name = r.r_constraint_name and
p.owner = r.r_owner and p.table_name != r.table_name) );
:DEPT:EMP
:T1:T4
:T1:T2:T3
:T5:T5

Similar Messages

  • Adding a Unique and Referential Constraint to  XMLType of Purchase Table

    SQL> desc XDBPO_TYPE
    XDBPO_TYPE is NOT FINAL
    Name Null? Type
    SYS_XDBPD$ XDB.XDB$RAW_LIST_T
    messageType VARCHAR2(4000)
    MessageHeader XDBPO_MESSAGEHEADER_TYPE
    Order XDBPO_ORDER_CLLT
    SQL> desc XDBPO_MESSAGEHEADER_TYPE
    XDBPO_MESSAGEHEADER_TYPE is NOT FINAL
    Name Null? Type
    SYS_XDBPD$ XDB.XDB$RAW_LIST_T
    version VARCHAR2(50)
    payloadId VARCHAR2(4000)
    transmissionAgent VARCHAR2(4000)
    timeStamp VARCHAR2(20)
    senderName VARCHAR2(150)
    senderComponent VARCHAR2(150)
    documentReferenceId VARCHAR2(50)
    documentReferenceIdType VARCHAR2(50)
    dataCleansingDocumentId VARCHAR2(50)
    singleTransaction VARCHAR2(4000)
    Configuration XDBPO_CONFIGURATION_TYPE
    HeaderIndexedAttribute XDBPO_HIATTRIBUTE_CLLT
    I following the example in the demo in
    Adding a Unique and Referential Constraint to Table Purchaseorder
    which the constraint is added to the reference field.
    but for my case, i need to add my constraint
    to MessageHeader/@payloadId
    how do i go about in adding the constraint?
    tried to use this syntax logic but not successful:
    alter table purchaseorder
    add constraint REFERENCE_IS_UNIQUE
    unique (xmldata."Reference")
    Anyone have any idea? Mark?
    Thanks.

    nevermind i solved the problem already
    i will just post the solution incase someone else wants to add constraint to the sub xmltype object
    alter table purchaseorder
    add constraint REFERENCE_IS_UNIQUE
    unique (xmldata."MessageHeader"."payloadId");

  • Scope keyword and referential constraints

    Hi guys,
    I'm new in DB relational-object, and looking at oracle guide
    I have foud that I can specify both scope and referential constraint using the keyword REFERENTIAL associated with keyword SCOPE FOR
    ([http://download-east.oracle.com/docs/cd/B14117_01/appdev.101/b10799/adobjbas.htm#sthref108] basic component of oracle object)
    Now, I checked that SCOPE FOR work properly:
    ALTER TABLE SOME_TAB ADD (SCOPE FOR (ATTRIBUE_SOME_TAB) IS ANOTHER_TAB);
    but I can't specify REFERENTIAL constraint in any way and
    neither I have founf some explanation about
    Have Someone idea about this?
    Thanks, for your helps to me!

    See:
    Re: to REF or not to REF?
    "To avoid dangling REFs, we must have good old foreign key:
    ALTER TABLE emp_obj_tab ADD CONSTRAINT emp_dept_fk FOREIGN KEY (dept_oid) REFERENCES dept_obj_tab;"
    Regards

  • Hierarchal queries and USER_DEPENDENCIES

    I'm new to Hierarchal queries; I have a Hierarchal query on USER_DEPENDENCIES that does not work and gives an error
    'TSPKG_ES' is a package the works; I'm trying to do query to see what is calls
    SELECT LEVEL, D.*
    FROM DBA_DEPENDENCIES D
    START WITH D.name = 'TSPKG_ES'
    CONNECT BY PRIOR D.name = D.referenced_name
    Result = ORA-00600: internal error code, arguments: [sorsikbeg_1], [5], [0] ,[],[],[],[],[]
    SELECT LEVEL, D.*
    FROM DBA_DEPENDENCIES D
    START WITH D.name = 'DATATESTSPKG_ES'
    CONNECT BY PRIOR D.referenced_name = D.name
    Result = ORA=0143: CONNECT BY loop in user data

    OS = Microsoft Windows XP V2002 Service Pack 3
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    "CORE     10.2.0.4.0     Production"
    TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production

  • SELECT, hierarchical queries and JOIN

    Hi everyone,
    I have a small SELECT statement but I can't find an easy solution.
    Look at this situation:
    drop table departments;
    CREATE TABLE departments
      dpt_id NUMBER(10) UNIQUE,
      dpt_name VARCHAR2(100),
      dpt_parent_id NUMBER(10)
    TRUNCATE table departments;
    INSERT INTO departments VALUES(1, 'Company', null);
    INSERT INTO departments VALUES(2, 'HR', 1);
    INSERT INTO departments VALUES(3, 'SALES', 1);
    INSERT INTO departments VALUES(4, 'IT', 1);
    INSERT INTO departments VALUES(222, 'Helpdesk', 4);
    INSERT INTO departments VALUES(223, 'French Speaking', 222);
    INSERT INTO departments VALUES(224, 'Another level', 223);
    INSERT INTO departments VALUES(5, 'LEGAL', 1);
    INSERT INTO departments VALUES(66, 'Recruitment', 2);
    INSERT INTO departments VALUES(33, 'Logistics', 2);
    INSERT INTO departments VALUES(39, 'Fleet management', 33);
    INSERT INTO departments VALUES(31, 'Local Sales', 3);
    INSERT INTO departments VALUES(60, 'European Sales', 3);
    INSERT INTO departments VALUES(61, 'Germany', 60);
    INSERT INTO departments VALUES(62, 'France', 60);
    INSERT INTO departments VALUES(620, 'Paris', 62);
    INSERT INTO departments VALUES(621, 'Marseilles', 62);
    INSERT INTO departments VALUES(38, 'American Sales', 3);
    INSERT INTO departments VALUES(34, 'Asian Sales', 3);
    CREATE table persons
      person_id NUMBER(10) UNIQUE,
      person_name VARCHAR2(100),
      person_dpt_id NUMBER(10)
    truncate table persons;
    INSERT INTO persons VALUES(1, 'Jim', 2);
    INSERT INTO persons VALUES(2, 'Jack', 621);
    INSERT INTO persons VALUES(3, 'John', 620);
    INSERT INTO persons VALUES(4, 'John', 224);
    INSERT INTO persons VALUES(5, 'Fred', 61);It's a simple hierachy like the one we can find in HR schema. The link between an department and its parent is with parent id. THe following statement build the whole tree:
    SELECT dpt_id, level, LPAD(' ', LEVEL-1)|| dpt_name
      FROM departments
    START WITH dpt_parent_id IS NULL
    CONNECT BY dpt_parent_id = PRIOR dpt_id;As you can see in the script above, I have a few people assigned to these departments. It's also a classic situtation...
    I would like to have something like this:
    WITH temp AS
      SELECT dpt_id, dpt_name, SYS_CONNECT_BY_PATH(dpt_name, '#') as full_path
        FROM departments
       START WITH dpt_parent_id IS NULL
    CONNECT BY dpt_parent_id = PRIOR dpt_id
    SELECT p.person_name, d.dpt_name, --d.full_path,
           regexp_substr(d.full_path, '[^#]+', 1, 2, 'i') as t1,
           regexp_substr(d.full_path, '[^#]+', 1, 3, 'i') as t2,
           regexp_substr(d.full_path, '[^#]+', 1, 4, 'i') as t3,
           regexp_substr(d.full_path, '[^#]+', 1, 5, 'i') as t4
      FROM persons p
      JOIN temp d ON d.dpt_id = p.person_dpt_id;This is the exact output I want, but I wonder... Is it possible to do it without the factored sub-query? It's nice and works fine but I had to precompute the whole path to split it again. I mean, this should be possible in one step. Any suggestion?
    I'm using Oracle 10g
    Thanks,

    Hi,
    user13117585 wrote:
    ... But sometimes, I just find the statements difficult for what they do. For example, my previous one. I have a person, and I want to see his department and the path in the tree.Actually, you want more than that; you want to parse the path, and display each #-delimited part in a separate column. If you didn't want that, then you could do away with the 4 REGEXP_SUBSTR calls, like this:
    WITH temp AS
      SELECT dpt_id, dpt_name
      ,       SUBSTR ( REPLACE ( SYS_CONNECT_BY_PATH ( RPAD (dpt_name, 15)     -- Using 15 just for demo
               , 16
               )     as full_path
        FROM departments
       START WITH dpt_parent_id IS NULL
    CONNECT BY dpt_parent_id = PRIOR dpt_id
    SELECT p.person_name, d.dpt_name, d.full_path
      FROM persons p
      JOIN temp d ON d.dpt_id = p.person_dpt_id;Output:
    PERSON_N DPT_NAME      FULL_PATH
    Jim      HR            HR
    Fred     Germany       SALES          European Sales Germany
    John     Paris         SALES          European Sales France         Paris
    Jack     Marseilles    SALES          European Sales France         Marseilles
    John     Another level IT             Helpdesk       French SpeakingAnother levelAs you can see, full_path is one giant column, but it's formatted to look like 4 separate columns, forresponding to your original t1, t2, t3 and t4. I limited the output to 15 characters, just for debugging and posting purposes. You can use any number of characters you like.
    It's too complex for this simple thing.It would be nice if there was something simpler that did exactly what you wanted, but I'm not sure it's reasonable to expect it in every case. I asked a lot of questions in my first message, but I'm not sure you've tried to answer any of them, so I'm not sure why you're unhappy with the query you posted. I can think of lots of ways to change the query, but I have no way of telling if you would like them any better than what you already have.
    And hopefully, I know where to start in the hierarchy and I know where to stop. If I had to show all the levels and have one column by level dynamically, I'd be stuck. Sorry, I don't understand this part.
    Are you saying that it seems inefficient to generate the entire tree, when perhaps few of the nodes will have have matches in the persons table? If so, you can invert the whole query. Instead of doing the CONNECT BY first and then joining, do the join first and then the CONNECT BY. Instead of doing a top-down CONNECT BY, where you start with the parentless nodes (whether or not you'll ultimately need them) and then find their descendants, do a bottom-up CONNECT BY, where you start with the nodes you know you'll need, and then find their ancestors.
    I just find it difficult for such a simple need. Again, there are lots of things that could be done. If you won't say what you want, that makes it hard for me to tell you how to get it. All that I've picked up for sure is that you don't like doing a sub-query. That's unfortunate, because sub-queries are so basic. They have very important been since Oracle 8.1, and they don't seem to be going away. Quite the opposite, in fact. You need sub-queries for all kinds of things, not just CONNECT BY. To give just a couple of examples, they're the only thing that make analytic functions really useful, and they simplfy chasm traps (basically, multiple 1-to-many relationships on the same table) considerably. I'm sorry if you don't lke sub-queries, but I don't see how you can work in this field and not use them.
    Edited by: Frank Kulash on Nov 15, 2011 3:18 PM
    Revised query

  • Hierarchical queries and nested tables

    Hallo,
    Assume you have the following data structure:
    SQL> desc mgr
    Name Null? Typ
    MGRNO NUMBER
    LASTNAME VARCHAR2(20)
    EMPS EMPTYPE_TAB
    SQL> desc emptype_tab
    emptype_tab TABLE OF EMP_TYPE
    Name Null? Typ
    EMPNO NUMBER
    LASTNAME VARCHAR2(20)
    I would like to select rows in a hierarchical order to get an output like this:
    LAST_NAME EMPNO MGRNO LEVEL
    King 100 1
    Cambrault 148 100 2
    Bates 172 148 3
    ..but i have absolutely no clue how to use the hierarchical query clause with a nested table.
    can anybody help me?

    scott@ORA92> CREATE OR REPLACE TYPE emp_type AS OBJECT
      2    (empno      NUMBER,
      3       lastname VARCHAR2(20))
      4  /
    Type created.
    scott@ORA92> CREATE OR REPLACE TYPE emptype_tab AS TABLE OF emp_type
      2  /
    Type created.
    scott@ORA92> CREATE TABLE mgr
      2    (MGRNO      NUMBER,
      3       LASTNAME VARCHAR2(20),
      4       EMPS      EMPTYPE_TAB)
      5    NESTED TABLE emps STORE AS emps_nt
      6  /
    Table created.
    scott@ORA92> INSERT INTO mgr VALUES (NULL, NULL, emptype_tab (emp_type (100, 'King')))
      2  /
    1 row created.
    scott@ORA92> INSERT INTO mgr VALUES (100, 'King', emptype_tab (emp_type (148, 'Cambrault')))
      2  /
    1 row created.
    scott@ORA92> INSERT INTO mgr VALUES (148, 'Cambrault', emptype_tab (emp_type (172, 'Bates')))
      2  /
    1 row created.
    scott@ORA92> SELECT * FROM mgr
      2  /
         MGRNO LASTNAME
    EMPS(EMPNO, LASTNAME)
    EMPTYPE_TAB(EMP_TYPE(100, 'King'))
           100 King
    EMPTYPE_TAB(EMP_TYPE(148, 'Cambrault'))
           148 Cambrault
    EMPTYPE_TAB(EMP_TYPE(172, 'Bates'))
    scott@ORA92> SELECT m.mgrno, m.lastname as mgr, e.empno, e.lastname as emp
      2  FROM   mgr m, TABLE (emps) e
      3  /
         MGRNO MGR                       EMPNO EMP
                                           100 King
           100 King                        148 Cambrault
           148 Cambrault                   172 Bates
    scott@ORA92> SELECT lastname, empno, mgrno, LEVEL
      2  FROM   (SELECT m.mgrno, e.lastname, e.empno
      3            FROM   mgr m, TABLE (emps) e)
      4  START  WITH mgrno IS NULL
      5  CONNECT BY PRIOR empno = mgrno
      6  /
    LASTNAME                  EMPNO      MGRNO      LEVEL
    King                        100                     1
    Cambrault                   148        100          2
    Bates                       172        148          3
    scott@ORA92>

  • Hierarchical Queries help me

    hi,
    What is the usage of 'Connect' , 'Prior' in hierarchical queries and
    what does it mean??

    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm
    Cheers
    Sarma.

  • To create referential constraints or not while designing a data model...

    Hi,
    If I were to design a data model involving some tables which tend to grow fast and huge, which option w.r.t creating referential constraints (foreign key constraints) between tables is advisable - to create or not to create?
    Assuming that there are no specific requirements to implement referential integrity (though it maybe implicity stated). I know that creating referential constraints might maintain data integrity but on the other hand, it might be a bottleneck in some data-intensive queries/operations involving huge tables.
    In other words, what factors should we consider while deciding on to create referential constraints or not in a data model?
    thanks & regds,
    Ashok.

    Hi,
    >>it might be a bottleneck in some data-intensive queries/operations involving huge tables.
    Hummm, are you sure ? I'm not convinced that foreign key constraints can cause a bottlenecks while querying the database. Why ? Otherwise, DML statements can be affected by some constraints and indexes ... in some systems for example perform data loading in a Data Warehouse, DSS Systems, etc....
    "The key thing to remember here is that if you cannot guarantee the integrity of your data, it doesn't matter how fast you can retrieve it from the database"
    Cheers

  • Help needed in understanding the concept of hierarchical queries

    I really need help in this matter. I have a flafile containing about 4000 rows. It is from my supplier, it's structure is as follows:
    create table Flatfile
    (Pgroup varchar2(30),
    Pclass varchar2(30),
    Manufacturer varchar2(30),
    Article varchar2(30),
    Price Number(6,2));
    Insert into Flatfile Values
    ('Application Software','Database Software','Oracle','Oracle 10G',115);
    Insert into Flatfile Values
    ('Application Software','Database Software','Microsoft','MS SQL Server 2000',200);
    Insert into Flatfile Values
    ('Application Software','Spreadsheet Software','Microsoft','Excel',100);
    Insert into Flatfile Values
    ('Monitor','15"','Acer','Acer 15"" TFT superscreen',199);
    Insert into Flatfile Values
    ('Monitor','15"','Sony','Sony R1500 flat',225);
    Insert into Flatfile Values
    ('Monitor','17"','Philips','Philips Flatscreen',250);
    Insert into Flatfile Values
    ('Monitor','19"','Viewsonic','Viewsonic PLasma Monitor',275);
    Insert into Flatfile Values
    ('Processor','AMD','AMD','FX-55',600);
    Insert into Flatfile Values
    ('Processor','Intel','Intel','P4 3 GHZ',399);
    My goal is to make a hierarchical query with the start with and connect by clauses. From what I have read is that I need to normalize the data of the flatfile.
    How do I achieve a table which I can query so that the query will represent the hierarchy that exists. Namely
    Pgroup
    ++Pclasse
    Application Software
    ++Database Software
    ++Spreadsheet Software
    So a 2-level hierarchy. I'd like to understand this simple concept first. I built on the knowledge that I gain. So the questions are:
    1.What do I need to do to make the table so that I can use a hierarchical query on it?
    2. How should the query syntax be?
    3. Is it also possible to get the data in the hierarchical query sorted asec?
    I would only like to use the simple structures of the start with and connect by clauses first. I've read there are some new additions to 10G. The problem with the examples used by the tutorials is that the tables are already made so that they are suitable for hierarchical queries. I hope to understand it by this example. And take it a step further.
    Sincerely,
    Pete

    Primarily hierarchy query serves to process tree-like structures which RDBMS simulates using through parent-child relation, often in a single table (see famoust
    EMP table where employee can have the manager who is an employee at the same time).
    In your case it could look like:
    SQL> select pgroup, pclass from flatfile;
    PGROUP                         PCLASS
    Application Software           Database Software
    Application Software           Database Software
    Application Software           Spreadsheet Software
    Monitor                        15"
    Monitor                        15"
    Monitor                        17"
    Monitor                        19"
    Processor                      AMD
    Processor                      Intel
                                   Application Software
                                   Monitor
                                   Processor
    12 rows selected.
    SQL> select decode(level,1,pclass,'  ' || pclass), Manufacturer from flatfile
      2  start with pgroup is null
      3  connect by prior pclass = pgroup
      4  /
    DECODE(LEVEL,1,PCLASS,''||PCLASS MANUFACTURER
    Application Software
      Database Software              Oracle
      Database Software              Microsoft
      Spreadsheet Software           Microsoft
    Monitor
      15"                            Acer
      15"                            Sony
      17"                            Philips
      19"                            Viewsonic
    Processor
      AMD                            AMD
      Intel                          Intel
    12 rows selected.The hierarchy syntax is described completely in the documentation including
    LEVEL and PRIOR keywords.
    As for the ordering question you can use siblings ordering:
    SQL> select decode(level,1,pclass,'  ' || pclass), Manufacturer from flatfile
      2  start with pgroup is null
      3  connect by prior pclass = pgroup
      4  order siblings by 1 desc
      5  /
    DECODE(LEVEL,1,PCLASS,''||PCLASS MANUFACTURER
    Processor
      Intel                          Intel
      AMD                            AMD
    Monitor
      19"                            Viewsonic
      17"                            Philips
      15"                            Acer
      15"                            Sony
    Application Software
      Spreadsheet Software           Microsoft
      Database Software              Oracle
      Database Software              Microsoft
    12 rows selected.Rgds.

  • Incorrect order for referential constraints in Export

    When multiple tables are selected to export, the created file places the ALTER TABLE statements for the Referential Constraints immediately after the creation of the source table. Unfortunately, most of the time this will mean that the referenced table has not yet been created and the statement will fail.
    All referential constraints should be created as a separate block of statements at the end of the file rather than table by table where errors will occur if the script is simply run.

    I managed to resolve the issue by un-commenting below lines( they were commented in std though) -
    XDECI FILL IT & XDECI FILL RT

  • Alternative for Hierarchical Queries

    Hi all,
    Is there any other way to implement the Hierachical Query in Oracle. Let us assume the following example of the Scott.emp Table. The output of the table must be in a Hierarchical manner as follows :
    ORG_CHART EMPNO MGR JOB
    KING 7839 PRESIDENT
    JONES 7566 7839 MANAGER
    SCOTT 7788 7566 ANALYST
    ADAMS 7876 7788 CLERK
    FORD 7902 7566 ANALYST
    SMITH 7369 7902 CLERK
    BLAKE 7698 7839 MANAGER
    ALLEN 7499 7698 SALESMAN
    WARD 7521 7698 SALESMAN
    MARTIN 7654 7698 SALESMAN
    TURNER 7844 7698 SALESMAN
    JAMES 7900 7698 CLERK
    CLARK 7782 7839 MANAGER
    MILLER 7934 7782 CLERK
    The above structure can be achieved using the following implementation by using the clauses namely CONNECT BY PRIOR, LEVEL and START WITH :
    SELECT LPAD(' ',2*(LEVEL-1)) || ename org_chart,
    empno, mgr, job
    FROM emp
    START WITH job = 'PRESIDENT'
    CONNECT BY PRIOR empno = mgr;
    The above query works fine without any issues.
    But is there any other way to implement the above logic without using the above hierarchical query clauses.
    Please help me on the above.
    Thanks in advance.
    Regards
    Raj

    Thanks.
    Why I require this implementation is we have an software which runs both on Oracle and SQL Server, we accomplish the same very easily in Oracle by using the Hierarchical Queries already available in Oracle. But there is no such predefined keywords to implement in SQL server. That is the purpose of the above.
    When we can achieve the same in a alternative way in Oracle, the same I feel can be implemented in SQL server.
    Raj
    Not without dropping into PLSQL, but this is not easy, and why bother, if your query works OK?

  • Map the hierarchical queries pseudo column level

    Is it possible to map the hierarchical queries pseudo column level in the Workbench?
    I have an object for which I use connect by queries. I would like to map the pseudo column level. is this possible? if yes, how
    If the mapping is not possible how do I get the level using a report query?
    Is there any other way to retrive level?
    Thanks
    Edited by: amehta5 on May 4, 2010 11:52 AM
    Edited by: amehta5 on May 4, 2010 11:55 AM

    Thanks James, appreciate your feedback.
    I tried report.addItem("level", builder.getFunction("LEVEL"));
    but the query TopLink generates has LEVEL() and it errors out.
    Code -
    Expression startExpr = null;
    Expression connectBy = builder.get("manager");
    Vector<Expression> order = new Vector<Expression>();
    order.addElement(builder.get("name"));
    report.setHierarchicalQueryClause(startExpr, connectBy, order);
    report.addAttribute("name");
    report.addItem("level", builder.getFunction("LEVEL"));
    Query generated by TOpLink - SELECT NAME, ID, LEVEL() FROM EMPLOYEE WHERE (EMPLOYEE_TYPE = ?) CONNECT BY PRIOR EMPLOYEE.MANAGER_ID = EMPLOYEE.ID ORDER SIBLINGS BY NAME
    bind => [M]
    Edited by: amehta5 on May 6, 2010 6:11 AM

  • Referential constraints on XMLType tables

    Hi all,
    I'm trying to create an XMLType table with a foreign key that references another XMLType table. Shouldn't be a big deal, i thought.
    CREATE TABLE datasets (
    ID NUMBER,
    XML XMLTYPE )
    XMLTYPE COLUMN XML XMLSCHEMA "dataset_schema.xsd" ELEMENT "root";
    CREATE TABLE categories OF XMLTYPE XMLSCHEMA "categories.xsd" ELEMENT "categories";
    ALTER TABLE datasets
    2 ADD CONSTRAINT dataset_isvalid
    3 FOREIGN KEY(XML.XMLDATA."dataset"."metaInformation"."referenceFunction"."category")
    4 REFERENCES categories(XMLDATA."category"."name");
    FOREIGN KEY(XML.XMLDATA."dataset"."metaInformation"."referenceFunction"."category")
    ERROR at line 3:
    ORA-22809: nonexistent attribute
    I've then been reading through the postings regarding foreign key and unique constraints and i've managed to understand the concept of nested tables. To my dismay, trying to establish referential constraints my nested tables would throw an ORA-30730 stating this cannot be done.
    I've simplified my schemas a little so it won't get to complicated: one table will store datasets and the other will hold category names.
    The schema for the categories is
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- schema for categories -->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
         <xs:element name="categories">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="category" type="categoryType" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:complexType name="categoryType">
              <xs:sequence>
                   <xs:element name="subCategory" type="subCategoryType" maxOccurs="unbounded"/>
              </xs:sequence>
              <xs:attribute name="name" type="xs:string" use="required"/>
              <xs:attribute name="localName" type="xs:string" use="required"/>
              <xs:attribute name="type" type="xs:byte" use="required"/>
         </xs:complexType>
         <xs:complexType name="subCategoryType">
              <xs:attribute name="name" type="xs:string" use="required"/>
              <xs:attribute name="localName" type="xs:string" use="required"/>
         </xs:complexType>
    </xs:schema>
    and the schema for the dataset table is
    <?xml version="1.0" encoding="UTF-8"?>
    <!- dataset schema-->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
         <xs:complexType name="datasetType">
              <xs:sequence>
                   <xs:element name="metaInformation" type="metaInformationType"/>
                   <xs:element ref="otherInformation"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="metaInformationType">
              <xs:sequence>
                   <xs:element name="referenceFunction" type="referenceFunctionType"/>
              </xs:sequence>
         </xs:complexType>
         <xs:element name="otherInformation" type="xs:string"/>
         <xs:complexType name="referenceFunctionType">
              <xs:attribute name="name" type="xs:string" use="required"/>
              <xs:attribute name="category" type="xs:string" use="required"/>
              <xs:attribute name="subCategory" type="xs:string" use="required"/>
         </xs:complexType>
         <xs:element name="root">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="dataset" type="datasetType" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
    </xs:schema>
    Now I want to define the referenceFunction/@category attribute of the dataset to be a foreign key to the categories table. Is it possible at all to do that with constraints? After failing with the nested table approach I really do not have any clue I would greatly appreciate any hints.
    Thanks,
    oli

    Nested tables do not currently support referential integrity.
    Foreign Keys on elements with maxOccurs > 0

  • Hierarchical queries (mother, father,...)

    Hi guys,
    a have a problem that I think it can be solved whit hierarchical queries.
    the question is like this. I have a person ...and each person has a mother and a father. (the mother/father may be or not be in my table)
    so my table configuration will be like:
    create table person
    (id number,
    name varchar2 (100),
    mother_id number,
    father_id number
    the questions I need to answer are like:
    1. return all persons that have all grandparents (or grand grand parents) in this table.(including parents). so entire genealogic tree is intact
    e.g. if the grandfather is not in the table I will not display that person we cannot display that person
    I have something like:
    insert into person values (1,'alin', 4, 5); ----id 1 has parents in my table: 4 the mother, 5 the father
    insert into person values (4,'mother_1', 8,null); ----id 4 has only her mother in table
    insert into person values (5, 'father_1',9,10);--id 5(who is father of 1) with 9 as mother and 10 as father
    insert into person values (8, 'grant',null ,null );
    insert into person values (9, 'aaa',11,12);
    insert into person values (10,'bbb',13,14);
    insert into person values (11,'ccc',null ,null);
    insert into person values (12, 'ddd',null ,null);
    insert into person values (13,'eee',15,16);
    insert into person values (14,'fff',17,18);
    insert into person values (15,'ggg',null ,null);
    insert into person values (16,'hhh',null ,null);
    insert into person values (17,'iii',null ,null);
    insert into person values (18,'jjjj',null,null);
    in this configuration my select should return id 5 with his relatives and id 10 with this relatives because only them have all relatives in table:
    id         |         name      |          mother    |      father      |      mather_mother (mm)   |        father_mother  (fm)  |      mf    |        ff   
    5          |         'father'    |           9           |      10      |              11            |            12              |     13     |      14
    10        |          bbb        |           13         |      14      |                15            |             16              |       17   |        18
    and second select ..if I input an id..lets say 1 to get the same result..like:
    id        |          name         |       mother     |     father   |         mather_mother (mm) |         father_mother  (fm) |       mf   |         ff   
    1         |         'alin'           |      4              |   5           |             8           |       null           |      9       |     10and maybe at some point I want to show level 3(with grand grand parents)
    please se the attached picture:
    link: [http://picasaweb.google.com/alinbor/Tree#5428860555382426514]
    Thanks

    Hi,
    Here's a revised version of the String Aggregation approach.
    For :level_cnt = 3, it produces this output:
       ROOT_ID ROOT_NAME  ANCESTORS
                              M    F   MM   FM   MF   FF
             5 father_1       9   10   11   13   12   14
            10 bbb           13   14   15   17   16   18The last part, starting with UNION, gets the "header " row.
    The first part, before UNION, is exactly what I posted yesterday.
    WITH     got_tree   AS
         SELECT     id
         ,     name
         ,     CONNECT_BY_ROOT id     AS root_id
         ,     CONNECT_BY_ROOT name     AS root_name
         ,     LEVEL               AS level_num
         ,     CASE
                   WHEN  id = PRIOR mother_id
                   THEN  'M'
                   ELSE  'F'
              END               AS mf_flag
         ,     SYS_CONNECT_BY_PATH ( CASE
                               WHEN  id = PRIOR mother_id
                               THEN  'M'
                               ELSE     'F'
                              END
                            )     AS gender_path
         FROM     person     p
         CONNECT BY     (     id     = PRIOR mother_id
                       OR     id     = PRIOR father_id
              AND     LEVEL     <= :level_cnt
    ,     got_sa_num     AS
         SELECT     t.*
         ,     ROW_NUMBER () OVER ( PARTITION BY  root_id
                                   ORDER BY          level_num
                             ,                mf_flag     DESC
                             ,             gender_path     DESC
                           )      AS sa_num
         FROM     got_tree        t
    SELECT     root_id
    ,     root_name
    ,     REPLACE ( SYS_CONNECT_BY_PATH ( TO_CHAR (id, '9999')
              )     AS ancestors
    FROM     got_sa_num
    WHERE     sa_num     = POWER (2, :level_cnt) - 1
    START WITH     sa_num     = 2
    CONNECT BY     sa_num     = PRIOR sa_num + 1
         AND     root_id     = PRIOR root_id
        UNION
    SELECT      NULL          AS root_id
    ,     NULL          AS root_name
    ,     REPLACE ( SYS_CONNECT_BY_PATH ( LPAD ( SUBSTR ( REPLACE ( gender_path
                                        , 2
                                  , 5     -- 1 + number of '9's in TO_CHAR, 13 lines up
              )     AS ancestors
    FROM     got_sa_num
    WHERE     sa_num     = POWER (2, :level_cnt) - 1
    START WITH     sa_num     = 2
    CONNECT BY     sa_num     = PRIOR sa_num + 1
         AND     root_id     = PRIOR root_id
    ORDER BY  root_id     NULLS FIRST
    ;

  • Hierarchical Queries / Rowsets via JDBC?

    I have an application that requires data from an SQL database to be displayed in a hierarchical directed graph (i.e. a JTree). Is it possible to construct Hierarchical Queries that return Hierarchical Rowsets in servlets via JDBC? This would be akin to using a Microsoft ADODB Hierarchical Recordset object, but I need a Java solution that's portable and isn't dependent on proprietary extensions in a server (i.e. iPlanet, etc.).
    Any help would be appreciated.
    Thanks.

    Is it possible to construct Hierarchical Queries that
    return Hierarchical Rowsetsin servlets via JDBC?No. JDBC only speaks in flat rows and columns.
    What type of hierarchical rowset are you referring to? Is it multidimensional data? For example MSSqlServer OLAP with row, column and measure dimensions? Or, is it simply grouped data for which you are both summarizing and displaying detail?

Maybe you are looking for

  • 6500 slide

    hi, could anyone tell me how long to charge a new battery for manual says 1 hour 30 but does not say for first time charge

  • Cropping a series of photos in consistent format?

    I have a whole series of action-figure products that I shot in my studio, and I want to now crop each one in the same manner. How do I control the crop tool to apply the same crop to a series of photos?

  • Oracle Reports 2.5.5.20.0

    I have Oracle Reports 2.5.5.20.0 and I have external query in file. The file size is about 3 kb. Oracle Reports didn't allow me to insert this query. Why? null

  • I have problem my iPhone 4s contact name appear  I am in maldives

    IPhone 4s contact name not display when call come but contact numbers are save in contact list . And I have try contact number save with country code and without country code as same problems .

  • ¿Cómo se qué driver descargar para actualizar CUDA?

    Hola, he descargado after effects y me dice que mi versión CUDA es antigua y que debo actualizarla. ¿Cómo se cual es la versión que debo descargar desde NVIDIA? Esto es lo que tengo en información de CPU Borrador rápido: Disponible Memoria de la text