Problem inserting and querying XML data with a recursive XML schema

Hello,
I'm facing a problem with querying XML data that is valid against a recursive XML Schema. I have got a table category that stores data as binary XML using Oracle 11g Rel 2 on Windows XP. The XML Schema is the following:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="bold_type" mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="bold" type="bold_type"/>
               <xs:element name="keyword" type="keyword_type"/>
               <xs:element name="emph" type="emph_type"/>
          </xs:choice>
     </xs:complexType>
     <xs:complexType name="keyword_type" mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="bold" type="bold_type"/>
               <xs:element name="keyword" type="keyword_type"/>
               <xs:element name="emph" type="emph_type"/>
               <xs:element name="plain_text" type="xs:string"/>
          </xs:choice>
     </xs:complexType>
     <xs:complexType name="emph_type" mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="bold" type="bold_type"/>
               <xs:element name="keyword" type="keyword_type"/>
               <xs:element name="emph" type="emph_type"/>
          </xs:choice>
     </xs:complexType>
     <xs:complexType name="text_type" mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="bold" type="bold_type"/>
               <xs:element name="keyword" type="keyword_type"/>
               <xs:element name="emph" type="emph_type"/>
          </xs:choice>
     </xs:complexType>
     <xs:complexType name="parlist_type">
          <xs:sequence>
               <xs:element name="listitem" minOccurs="0" maxOccurs="unbounded" type="listitem_type"/>
          </xs:sequence>
     </xs:complexType>
     <xs:complexType name="listitem_type">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="parlist" type="parlist_type"/>
               <xs:element name="text" type="text_type"/>
          </xs:choice>
     </xs:complexType>
     <xs:element name="category">
          <xs:complexType>
               <xs:sequence>
                    <xs:element name="name"/>
                    <xs:element name="description">
                              <xs:complexType>
                                        <xs:choice>
                                                       <xs:element name="text" type="text_type"/>
                                                       <xs:element name="parlist" type="parlist_type"/>
                                        </xs:choice>
                              </xs:complexType>
                    </xs:element>
                                                            </xs:sequence>
                                                            <xs:attribute name="id"/>
                                        </xs:complexType>
                    </xs:element>
</xs:schema>I registered this schema and created the category table. Then I inserted a new row using the code below:
insert into category_a values
(XMlElement("category",
      xmlattributes('categoryAAA' as "id"),
      xmlforest ('ma categ' as "name"),
      (xmlelement("description", (xmlelement("text", 'find doors blest now whiles favours carriage tailor spacious senses defect threat ope willow please exeunt truest assembly <keyword> staring travels <bold> balthasar parts attach </bold> enshelter two <emph> inconsiderate ways preventions </emph> preventions clasps better affections comes perish </keyword> lucretia permit street full meddle yond general nature whipp <emph> lowness </emph> grievous pedro')))    
The row is successfully inserted as witnessed by the results of row counting. However, I cannot extract data from the table. First, I tried using SqlPlus* which hangs up and quits after a while. I then tried to use SQL Developer, but haven't got any result. Here follow some examples of queries and their results in SQL Developer:
Query 1
select * from category
Result : the whole row is returned
Query 2
select xmlquery('$p/category/description' passing object_value as "p" returning content) from category
Result: "SYS.XMLTYPE"
now I tried to fully respect the nested structure of description element in order to extract the text portion of <bold> using this query
Query 3
select  xmlquery('$p/category/description/text/keyword/bold/text()' passing object_value as "p" returning content) from  category_a
Result: null
and also tried to extract the text portion of element <text> using this query
Query 4
select  xmlquery('$p/category/description/text/text()' passing object_value as "p" returning content) from  category_a
Result: "SYS.XMLTYPE".
On the other hand, I noticed, from the result of query 1, that the opening tags of elements keyword and bold are encoded as the less than operator "&lt;". This explains why query 3 returns NULL. However, query 4 should display the text content of <text>, which is not the case.
My questions are about
1. How to properly insert the XML data while preserving the tags (especially the opening tag).
2. How to display the data (the text portion of the main Element or of the nested elements).
The problem about question 1 is that it is quite unfeasible to write a unique insert statement because the structure of <description> is recursive. In other words, if the structure of <description> was not recursive, it would be possible to embed the elements using the xmlelement function during the insertion.
In fact, I need to insert the content of <description> from a source table (called category_a) into a target table (+category_b+) automatically .
I filled category_a using the Saxloader utility from an flat XML file that I have generated from a benchmark. The content of <description> is different from one row to another but it is always valid with regards to the XML Schema. The data is properly inserted as witnessed by the "select * from category_a" instruction (500 row inserted). Besides, the opening tags of the nested elements under <description> are preserved (no "&lt;"). Then I wrote a PL/SQL procedure in which a cursor extracts the category id and category name into varchar2 variables and description into an XMLtype variable from category_a. When I try to insert the values into a category_b, I get the follwing error:
LSX-00213: only 0 occurrences of particle "text", minimum is 1which tells that the <text> element is absent (actually it is present in the source table).
So, my third question is why are not the tags recognized during the insertion?
Can anyone help please?

Hello,
indded, I was using an old version of Sqlplus* (8.0.60.0.0) because I had a previous installation (oracle 10g XE). Instead, I used the Sqlplus* shipped with the 11g2database (version 11.2.0.1.0). All the queries that I wrote work fine and display the data correctly.
I also used the XMLSERIALIZE function and can now display the description content in SQL Developer.
Thank you very much.
To answer your question Marco, I registered the XML Schema using the following code
declare
  doc varchar2(4000) := '<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="bold_type" mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="bold" type="bold_type"/>
               <xs:element name="keyword" type="keyword_type"/>
               <xs:element name="emph" type="emph_type"/>
          </xs:choice>
     </xs:complexType>
     <xs:complexType name="keyword_type" mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="bold" type="bold_type"/>
               <xs:element name="keyword" type="keyword_type"/>
               <xs:element name="emph" type="emph_type"/>
               <xs:element name="plain_text" type="xs:string"/>
          </xs:choice>
     </xs:complexType>
     <xs:complexType name="emph_type" mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="bold" type="bold_type"/>
               <xs:element name="keyword" type="keyword_type"/>
               <xs:element name="emph" type="emph_type"/>
          </xs:choice>
     </xs:complexType>
     <xs:complexType name="text_type" mixed="true">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="bold" type="bold_type"/>
               <xs:element name="keyword" type="keyword_type"/>
               <xs:element name="emph" type="emph_type"/>
          </xs:choice>
     </xs:complexType>
     <xs:complexType name="parlist_type">
          <xs:sequence>
               <xs:element name="listitem" minOccurs="0" maxOccurs="unbounded" type="listitem_type"/>
          </xs:sequence>
     </xs:complexType>
     <xs:complexType name="listitem_type">
          <xs:choice minOccurs="0" maxOccurs="unbounded">
               <xs:element name="parlist" type="parlist_type"/>
               <xs:element name="text" type="text_type"/>
          </xs:choice>
     </xs:complexType>
     <xs:element name="category">
          <xs:complexType>
               <xs:sequence>
                    <xs:element name="name"/>
                    <xs:element name="description">
                              <xs:complexType>
                                        <xs:choice>
                                                       <xs:element name="text" type="text_type"/>
                                                       <xs:element name="parlist" type="parlist_type"/>
                                        </xs:choice>
                              </xs:complexType>
                    </xs:element>
                                                            </xs:sequence>
                                                            <xs:attribute name="id"/>
                                        </xs:complexType>
                    </xs:element>
</xs:schema>';
begin
  dbms_xmlschema.registerSchema('/xmldb/category_auction.xsd', doc,     LOCAL      => FALSE, 
        GENTYPES   => FALSE,  GENBEAN    => FALSE,   GENTABLES  => FALSE,
         FORCE      => FALSE,
         OPTIONS    => DBMS_XMLSCHEMA.REGISTER_BINARYXML,
         OWNER      => USER);
end;then, I created the Category table as follows:
CREATE TABLE category_a of XMLType XMLTYPE store AS BINARY XML
    XMLSCHEMA "xmldb/category_auction.xsd" ELEMENT "category";Now, there still remains a problem of how to insert the "description" content which I serialized as a CLOB data into another table as XML. To this purpose, I wrote a view over the Category_a table as follows:
CREATE OR REPLACE FORCE VIEW "AUCTION_XWH"."CATEGORY_V" ("CATEGORY_ID", "CNAME", "DESCRIPTION") AS
  select category_v."CATEGORY_ID",category_v."CNAME",
  XMLSerialize(content ( xmlquery('$p/category/description/*' passing object_value as "p" returning content)) as clob) as "DESCRIPTION"
  from  auction.category_a p, 
xmltable ('$a/category' passing p.Object_Value as "a"
columns  category_id varchar2(15) path '@id',
          cname varchar2(20) path 'name') category_v;Then, I wrote a procedure to insert data into the Category_xwh table (the source and target tables are slightly different: the common elements are just copied wereas new elements are created in the target table). The code of the procedure is the following:
create or replace PROCEDURE I_CATEGORY AS
v_cname VARCHAR2(30);
v_description clob ;
v_category_id VARCHAR2(15);
cursor mycursor is select category_id, cname, description from category_v;
BEGIN
open mycursor;
  loop
  /*retrieving the columns*/
  fetch mycursor into v_category_id, v_cname, v_description ;
  exit when mycursor%notfound;
  insert into category_xwh values
  (XMlElement("category",
      xmlattributes(v_category_id as "category_id"),
      xmlelement("Hierarchies", xmlelement("ObjHierarchy", xmlelement ("H_Cat"),
                                                           xmlelement ("Rollsup",
                                                                              (xmlelement("all_categories",
                                                                               xmlattributes('allcategories' as "all_category_id")))
    xmlforest (
              v_cname as "cat_name",
              v_description as "description")    
end loop;
  commit;
  close mycursor;
END I_CATEGORY;When I execute the procedure, I get the following error:
LSX-00201: contents of "description" should be elements onlyso, I just wonder if this is because v_description is considered as plain text and not as XML text, even if its content is XML. Do I need to use a special function to cast the CLOB as XML?
Thanks for your help.
Doulkifli

Similar Messages

  • Insert and query buttons missing on qbe customize

    I created a simple qbe report and enabled update, delete, insert, and query. If I use the 'customize' link on the portal development screen for the qbe, it gives me the insert and query buttons. But as a portlet added to a page, if you click on the customize at the top right of the qbe portlet, it omits the insert and query buttons. Why does this happen? In each case I am logged in as the same person. I even played with the priviledges, to no avail.
    Any suggestions?

    Hi Steve ,
    In Qbe Report the update , delete , insert buttons are for full page mode and will not appear in portlet mode .
    The portlet mode customization can only be used to change the data appearing in the report (this is in consistent with the other kinds of reports )
    As a work around a form can be provided to insert and update the data .
    Regards
    Medini

  • Error when querying OLAP data with BI answers

    Have been doing all the Lessons in "Using Oracle OLAP With Oracle BI Enterprise Edition 10g Release 3". Got till lesson 3 where I'm supposed to query the data with Answers but If I add any of the facts to the report, I get the following error:
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17003] Oracle gateway error: Unsupported data type 101. (HY000)
    SQL Issued: SELECT Customer."Ship To" saw_0, Measures.COST saw_1 FROM Global ORDER BY saw_0
    So I was wondering if anyone knows what the catch could be.
    Thanks in advance!

    Yes. Me too. I have the same issue and I don't find any information about it. Could anyone help ?

  • How can I make a query by date with several TDMS files?

    Hi,
    I have a project that can write and read TDMS files everyday (a file for each day with date and time). There, I can import those files to excel (I choose a file and load it). But, I have a question: How can I make a query by date with those TDMS files? I'd like make a time stamp for start date and stop date, where I could compare the TDMS file dates and sum the values that are in the channels where these files are similar. For example, I save a file with "02/01/2013" name, in other day "03/01/2013", in other day "04/01/2013"... so, i'd like put in time stamp for start date "02/01/2013" file and to stop date "04/01/2013" file, than, sum all values that range with my TDMS files existing. How can I make that? 
    Thanks all,
    Val 

    Hello Val_Auto.
    You're Brazilian, no? Me too. = ^ - ^ =
    I converted VI to version of your LabVIEW (8.5). Is attached in this reply.
    This VI search all your TDMS in a range of dates and join them in a single TDMS. I hope this is what you wanted.
    Query TDMS is the main VI. The TDMS VI Search changes the date format that out from calendar control (which is DD / MM / YYYY) to DD-MM-YYYY. This is because you can't name files using "/". I chose "-" but, if necessary, you should change to keep the same format of your TDMS files.
    If you have any doubt as to its operation or how to make changes to adapt VI for your application, keep at your disposal.
    Thank you for your contact; I hope have helped you and succeed in your application.
    Wesley Rocha
    Application Engineer
    National Instruments Brazil
    Visite a nossa comunidade em PORTUGUÊS!!!
    Attachments:
    Query TDMS.vi ‏62 KB
    tdms search.vi ‏24 KB

  • Very slow insert and query

    Dear Professionals:
    The insert and query become very slow and somtimes hang. It wasn't like this before .. Network people added 100 pc to the network .. most of them not using the databse only internet and we are all in the same network .. Can this slow down the database Oracle 9.2.0.1.0 OS w2k server ? And how to know that the slowness is from network and not from query or inserts ?
    Ahmed.

    Hi,
    >>Network people added 100 pc to the network .. most of them not using the databse only internet. Can this slow down the database Oracle 9.2.0.1.0 OS w2k server ?
    Maybe yes, maybe not, maybe a network performance problem ...
    If you try to execute these DML's (insert, ...) and querys directly on the Server, what's happen ?
    Cheers

  • 2 time zones during inserting and selecting the data.

    we have applied DST patch and DST JAVA patch sucessfuly on oracle 10.1.0.3 version database . After that we have problem
    It was noticed that it failing for the following 2 time zones during inserting and selecting the data.
    MST7
    HST10
    Please help me to solve this

    Try MetaLink. Lots of hits on ORA-1882.
    Specifically, Note 414590.1 "Time Zone IDs for 7 Time Zones Changed in Time Zone Files Version 3 and Higher, Possible ORA-1882 After Upgrade" sounds promising.
    -Mark

  • Unable to insert and retrieve Unicode data using Microsoft OLE DB Provider

    Hi,
    I have an ASP.NET web application that uses OLEDB connection to Oracle database.
    Database: Oracle 11g
    Provider: MSDAORA
    ConnectionString: "Provider=MSDAORA;Data Source=localhost;User ID=system; Password=oracle;*convertNcharLiterals*=true;"
    When I use SQL Develeoper client and add convertNcharLiterals=true; in sqldeveloper.conf then I am able to store and retrieve Unicode data.
    The character sets are as follows:
    Database character set is: WE8MSWIN1252
    National Language character set: AL16UTF16
    Select * from nls_database_parameters where parameter in ('NLS_CHARACTERSET','NLS_LENGTH_SEMANTICS','NLS_NCHAR_CHARACTERSET');
    PARAMETER VALUE ---------------------------------------
    NLS_CHARACTERSET WE8MSWIN1252
    NLS_LENGTH_SEMANTICS BYTE
    NLS_NCHAR_CHARACTERSET AL16UTF16
    I have a test table:
    desc TestingUni
    Name Null Type
    UNI1 VARCHAR2(20)
    UNI2 VARCHAR2(20)
    UNI3 NVARCHAR2(20)
    I execute the below mentioned query from a System.OleDb.OleDbCommand object.
    Insert into TestingUni(UNI3 ) values(N'汉语漢語');
    BUT when retrieving the same I get question marks (¿¿¿¿) instead of the Chinese characters (汉语漢語)
    Is there any way to add the above property(convertNcharLiterals) when querying the Oracle database from OLEDB connection?
    OR is there any other provider for Oracle which would help me solve my problem?
    OR any other help regarding this?
    Thanks

    using OraOLEDB Provider.
    set the environment variable ORA_NCHAR_LITERAL_REPLACE to TRUE. Doing so transparently replaces the n' internally and preserves the text literal for SQL processing.
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements003.htm#i42617

  • Export and import table data with Java

    I need a library for simple exporting and importing table data.
    The data should be exported to a SQL file with insert statements.
    I just want to tell the library the table name, the connection and where to store the file. The usage should be very simple.
    Are there any small libraries for this? Finished calsses and methods which I can just call?

    I need a library for simple exporting and importing
    table data.
    The data should be exported to a SQL file with insert
    statements.Every database has utilities to export/import data from tables. Take a look at your database manual.

  • Problems uninstalling and reinstalling iTunes data on Windows 7

    Hello,
    Can someone please help me out.
    I recently had problems with the backup data on my iPhone 5S. Whenever I would try and sync my phone with iTunes on Windows 7 the backup would get stuck.
    I read on one of the threads that previous backup data can be manually deleted fromApplication Data\Apple Computer\MobileSync\Backup\. I did so by first cut-pasting the old backup folder to my desktop and then I tried to backup my iPhone and it worked. However, when I tried to delete the old backup folder from my desktop the folder wouldn't go away. I restarted my pc and even ran it on safe mode to delete this folder but it just wouldn't go away. After that everytime I would try to even click on this 'corrupted' folder my system would get stuck but otherwise everything worked fine on my pc. So I thought maybe if I tried to reinstall iTunes I might be able to get rid of this folder. But, unfortunately, after I uninstalled iTunes I am not able to reinstall it on my pc. The instalation keeps giving an error.
    Again, I tried restarting and getting rid of the following folders that still existed (as mentioned on Apple Support):
    C:\Program Files\Bonjour
    C:\Program Files\Common Files\Apple\Mobile Device Support
    C:\Program Files\Common Files\Apple\Apple Application Support
    C:\Program Files\Common Files\Apple\CoreFP
    Still no success I am unable to delete the above folders and the 'corrupted' one. I have a lot of stuff on my phone which I haven't been able to backup for days now plus my computer gets stuck if I even go near that 'corrupted' folder (which I can't even move from my desktop).
    Can anyone please help me solve this problem. I need to delete the corrupted folder and install iTunes again.
    I would really appreciate your help. Thank you!

    See Troubleshooting issues with iTunes for Windows updates for tips on repairing the iTunes installation. One of the tools mentioned there, Unlocker, should be able to delete the folders that you are having trouble removing.
    tt2

  • Import and process larger data with SQL*Loader and Java resource

    Hello,
    I have a project to import data from a text file in a schedule. A lager data, with nearly 20,000 record/1 hours.
    After that, we have to analysis the data, and export the results into a another database.
    I research about SQL*Loader and Java resource to do these task. But I have no experiment about that.
    I'm afraid of the huge data, Oracle could be slowdown or the session in Java Resource application could be timeout.
    Please tell me some advice about the solution.
    Thank you very much.

    With '?' mark i mean " How i can link this COL1 with column in csv file ? "
    Attilio

  • APD query key date with variable for time dependent MD display attributes

    Hello,
    In a APD I use a query as a source with a query key date that is filled with a customer exit variable.
    When I run the query as a user, the time dependent MD display attributes look fine. However, when I use the query in an APD, I get no values for the time dependent display attributes.
    Any suggestions?
    Thanks

    Hi,
    Try to run query using RSCRM_BAPI Tcode, this you can also schedule in background
    Thanks
    Reddy

  • Insert and select blob data

    how do i insert and update data whose data type is blob
    create table sample (no number,name varchar2(50),photo blob);
    my photo is in the format of jpg at Location C:\photos\39876542.jpg
    now ho do i do this using sqlplus .
    searching for the commands .My oracle version is 10.2 on windows

    Better to go through oracle doc.
    But, here is a quick link that you may try ->
    http://arjudba.blogspot.com/2008/06/how-to-insert-blob-dataimage-video-into.html
    Regards.
    Satyaki De.

  • Report query XML schema error - Apex Listener 2

    I built a simple query: select * from emp in (Shared components > Report Query)
    When I try to download XML schema for this query (Source Query section) resulting xsd file contains this text: String index out of range: -1
    Shared Apex hosting: 4.2.2.0.0.11
    Print server: Apex Listener 2.0.1

    Hey Saymonc, we're you ever able to find the cause of this issue?  I'm having this happen to me as well.  When I begin using the Report Query functionality, the schema downloaded just fine.  I made an update to a query and began receiving this error.  Now I get the error for ALL of my report queries.  I tried removing them and recreating them, and I continue to receive this error in my schema file, no matter how simple the query.  The data will download just fine, and using the Test Report button works as well.
    Thanks,
    Chris

  • Ora-06502: variable length too long on report query xml schema download

    on shared components/report queries/edit report query/
    and downloading my queries in xml schema format (radio button).
    Get
    ORA-06502: PL/SQL: numeric or value error: raw variable length too long
    when i click the download button.
    EDIT:
    i want to add that i recently changed several columns in the database from 150 to 3000 chars long.
    Edited by: Manny Rodriguez on Oct 11, 2011 7:19 AM

    "4000 bytes is the ultimate maximum. you can say 4000 *characters* , but it'll always be limited to 4000 *bytes* . "
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1224836384599#201073000346459201\
    "The maximum length of the column is determined by the national character set definition. Width specifications of character data type NVARCHAR2 refer to the number of characters. The maximum column size allowed is 4000 bytes."
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements001.htm#SQLRF50976
    By the way, you're treating your numbers as STRINGS, remove the quotes around your zero's.

  • How to Generate and Register XML Schema

    Does any one know how to gererate Oracle type XML schema provided XML file and register to XMLType field?
    Thanks for any expert suggestion...

    The SQL statement below shows how one can register XML schema to an XMLType column:
    create table po_tab(
    id number,
    po sys.XMLType
    xmltype column po
    XMLSCHEMA "http://www.oracle.com/PO.xsd"
    element "PurchaseOrder";
    Similarly you can register XML schema to the INVDOC field in the your INVOICE table.
    Hope it helps
    Shefali
    (OTN team)

Maybe you are looking for

  • How do I open Gaming Apps on Macbook Pro

    All my gaming apps are sitting in iTunes on my new Macbook pro, but don't seem able to open or drag them anywhere to me to play them.  open perfectly ok on my iPad. Any ideas how these apps are opened and where to place them ?

  • My monitor looks 90 degrees to the right

    My monitor looks 90 degrees to the right. How can I fix this?

  • Cannot print all pages of Acrobat PDF! eg Cable bill. mWHY????

    All my bills are usually 2 or more pages. When I select "View printable PDF" no problem. However, when I try to print 2 or more pages all I ever get is the first page and in some instances not even that. At those times when I select "Print Preview" o

  • Syncing emails between iphone and macbook

    E mails currently arrive in my inbox on the Mac, and on the iphone. Can anyone advise what settings I need to use so that when I delete an email from either phone or Mac, it will also delete from the other. Thanks

  • Adobe reader still not working properly...

    My problem is this: Adobe Reader opens up the main window, remains up for about 2-3 seconds, then closes. No error dialogue boxes, nothing. It doesn't matter if I open a .pdf file directly, or just run the Reader executable. I've reinstalled; I've un