XMLTYPE as CLOB storage "inserting large xml document in xml type column"

Hi All,
i have a table containing an xml datatype(non schema based)
i would like to insert a large xml document in it
but an exception is thrown-->"string literal too long"
i tried to use bind variables as a solution"prepared statements as i write in java"
but it didn't work....as xml document is large
when i tried to change the column type to CLOB,it worked but without xml validataion,
although the xml type is mapped to a CLOB in storage, xml type couldn't insert the document
if anyone have a solution plz tell,i needed it urgently
thanks,in advance :-)

thx it was very useful :-)
but i am not having any success getting the following statement working using a JDBC connection pool rather than a hard coded URL connection
tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
it works with:
"jdbc:oracle:thin:@server:port:dbname"
Does NOT work with:
datasource.getConnection()
if anyone colud help...

Similar Messages

  • Inserting large xml data into xmltype

    Hi all,
    In my project I need to insert very large XML data into xmltype column.
    My table:
    CREATE TABLE TransDetailstblCLOB ( id number, data_xml XMLType) XmlType data_xml STORE AS CLOB;
    I am using JDBC approach to insert values. It works fine for data less than 4000 bytes when using preparedStatement.setString(1, xmlData). As I have to insert large Xml data >4000 bytes I am now using preparedStatement.setClob() methods.
    My code works fine for table which has column declared as CLOB expicitly. But for TransDetailstblCLOB where the column is declared as XMLTYPE and storage option as CLOB I am getting the error : "ORA-01461: can bind a LONG value only for insert into a LONG column".
    This error means that there is a mismatch between my setClob() and column. which means am I not storing in CLOB column.
    I read in Oracle site that
    When you create an XMLType column without any XML schema specification, a hidden CLOB column is automatically created to store the XML data. The XMLType column itself becomes a virtual column over this hidden CLOB column. It is not possible to directly access the CLOB column; however, you can set the storage characteristics for the column using the XMLType storage clause."
    I dont understand its stated here that it is a hidden CLOB column then why not I use setClob()? It worked fine for pure CLOB column (another table) then Why is it giving such error for XMLTYPE table?
    I am struck up with this since 3 days. Can anyone help me please?
    My code snippet:
    query = "INSERT INTO po_xml_tab VALUES (?,XMLType(?)) ";
              //query = "INSERT INTO test VALUES (?,?) ";
         // Get the statement Object
         pstmt =(OraclePreparedStatement) conn.prepareStatement(query);
         // pstmt = conn.prepareStatement(query);
         //xmlData="test";
    //      If the temporary CLOB has not yet been created, create new
         temporaryClob = oracle.sql.CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
         // Open the temporary CLOB in readwrite mode to enable writing
         temporaryClob.open(CLOB.MODE_READWRITE);
         log.debug("tempClob opened"+"size bef writing data"+"length "+temporaryClob.getLength()+
                   "buffer size "+temporaryClob.getBufferSize()+"chunk size "+temporaryClob.getChunkSize());
         OutputStream out = temporaryClob.getAsciiOutputStream();
         InputStream in = new StringBufferInputStream(xmlData);
    int length = -1;
    int wrote = 0;
    int chunkSize = temporaryClob.getChunkSize();
    chunkSize=xmlData.length();
    byte[] buf = new byte[chunkSize];
    while ((length = in.read(buf)) != -1) {
    out.write(buf, 0, length);
    wrote += length;
    temporaryClob.setBytes(buf);
    log.debug("Wrote lenght"+wrote);
         // Bind this CLOB with the prepared Statement
         pstmt.setInt(1,100);
         pstmt.setStringForClob(2, xmlData);
         int i =pstmt.executeUpdate();
         if (i == 1) {
         log.debug("Record Successfully inserted!");
         }

    try this, in adodb works:
    declare poXML CLOB;
    BEGIN
    poXML := '<OIDS><OID>large text</OID></OIDS>';
    UPDATE a_po_xml_tab set podoc=XMLType(poXML) WHERE poid = 102;
    END;

  • How to insert large xml file to XMLType column?

    Hi,
    I have a table with one column as XMLType(Binary XML storage option and Free Text Indexing). When i try to insert a large XML as long as 8kb, i'm getting an error ORA-01704:string literal too long.
    Insert into TEST values(XMLTYPE('xml HERE'));
    How to insert large XML values to XMLType column?
    Regards,
    Sprightee

    For a large XML file, you basically have two options - you can load the string directly as an XMLType, or you can load the string as a CLOB and cast it on the database side to an XMLType.
    If you decide to load the XML as XmlType client-side, then you may be interested to know that versions of Oracle after 11.2.0.2 support the JDBC 4.0 SQLXML standard. See the JDBC driver release documentation here:
    http://docs.oracle.com/cd/E18283_01/java.112/e16548/jdbcvers.htm#BABGHBCC
    If you want to load as a CLOB, then you'll need to use PreparedStatement's setClob() method, or allocate an oracle.sql.clob object.
    For versions before 11.2.0.2, you can create an XMLType with a constructor that includes an InputStream or byte[] array.
    HTH
    Edited by: 938186 on Jun 23, 2012 11:43 AM

  • Inserting a row in a schema-based xml type column

    i have problems while inserting a row in a schema-based xml type column
    it reports an error(schema and elemnt do not match)
    although they are matching if anyone can try it
    and if it worked plz send me the example

    SQL> DESC XML_TAB;
    Name Null? Type
    XML XMLTYPE
    SQL> INSERT INTO XML_TAB
    2 VALUES
    3 (xmltype('<request>
    4 <filter>(extshortname=bhagat)</filter>
    5 <attributes>dn</attributes>
    6 <context/>
    7 <scope>subtree</scope>
    8 </request>'));
    1 row created.
    If your problem persists,post ur lines of code..
    Good luck!!!
    Bhagat

  • Xml type column

    Hi,
    This is my first time ever working with xml type column. I have a xml type column with name,value pairs. This xml type column needs to be indexed. How can I index this column(which index is suitable)? Also can xml type column be used in where clause for the joins with another table columns.
    Thank You
    SK

    XMLTypes in 10.1 are extremely slow and extremely buggy.
    They're maginally better in 10.2 (with the exception of anything added in that release, most notably XQuery), although there are some disasterous bugs in 10.2 in functionality that was actually fine in 10.1 (e.g. memory leaks, scaling nightmares).
    The XML Respository (required for XSD registration and shredding) is very unstable and will cause performance issues and instance outages.
    This is on top of the intrinsic performance and volume inefficiencies involved with XML.
    If you store data in a (column,row) of a SQL table it needs to be atomic with respect to the context of the database. Hiding information inside XML in a column of a table means your data is no longer even in 1st normal form. Surely we can all agree that is a Bad Idea and contrary to any concept of good practise, at this late stage.
    Furthermore querying XML structures is complex, slow and inflexible due to the asymetric nature of hierarchies. And once your information is in it, you're stuck with the incompleteness of XPath and the inefficiency of XQuery. All the indices in the world won't save you.
    More still, it is almost impossible, and very expensive to constrain the data in the XML other than trivial domain and "data type" constraints. The constraints require procedural validation and are not immediate. So you can kiss goodbye to referential integrity and consistency even if you figure out how to implement them.
    Also "abstract clob" XMLType storage requires multiple full document copies for read consistency purposes, so you will cripple your instance and your storage overhead (typically rather kindly benchmarked at 3 times SQL volume) will exponentially run away.
    Just don't do it.

  • (updating xml value)adding an element in an xml type column

    Hi all,
    i hava a table that contains an xml-Type column (non schema based)
    i have inserted some data in it
    table:(id,xmlcolumn)
    ex:
    insert into t1 values(1,'<Chapters>
    <Chapter>ch1<Chapter>
    <Chapter>ch2<Chapter>
    </Chapters>')
    i need to add a new Chapter: <Chapter>ch3</Chapter>
    for the result of xml instance in the table to be:
    <Chapters>
    <Chapter>ch1<Chapter>
    <Chapter>ch2<Chapter>
    <Chapter>ch3<Chapter>
    </Chapters>
    plz if any one colud help

    SQL> DECLARE
      2      l_xml      XMLTYPE := XMLTYPE('<Chapters>
      3  <Chapter>ch1</Chapter>
      4  <Chapter>ch2</Chapter>
      5  </Chapters>');
      6      l_xsl      XMLTYPE;
      7      l_new_node VARCHAR2(100) := '<Chapter>ch3</Chapter>';
      8  BEGIN
      9      dbms_output.put_line('Before adding node:');
    10      dbms_output.put_line('----------------------------------------------------------------');
    11      dbms_output.put_line(l_xml.getStringVal());
    12      dbms_output.put_line('----------------------------------------------------------------');
    13      l_xsl := XMLTYPE('<?xml version="1.0"?>' ||
    14                       '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"' ||
    15                       ' version="1.0"' || ' result-ns=""' || ' indent="no">' ||
    16                       '<xsl:output method="xml" media-type="text/xml" indent="no"/>' ||
    17                       '<xsl:template match="/">' ||
    18                           '<' ||l_xml.getRootElement() || '>' ||
    19                               ' <xsl:for-each select="/' || l_xml.getRootElement() ||'/Chapter">' ||
    20                                   '<xsl:copy-of select="." />' ||
    21                               '</xsl:for-each>' ||
    22                               l_new_node ||
    23                           '</' || l_xml.getRootElement() || '>' ||
    24                       '</xsl:template>' ||
    25                       '</xsl:stylesheet>');
    26      l_xml := l_xml.Transform(l_xsl);
    27      dbms_output.put_line('After adding node:');
    28      dbms_output.put_line('----------------------------------------------------------------');
    29      dbms_output.put_line(l_xml.getStringVal());
    30      dbms_output.put_line('----------------------------------------------------------------');
    31  END;
    32  /
    Before adding node:
    <Chapters>
    <Chapter>ch1</Chapter>
    <Chapter>ch2</Chapter>
    </Chapters>
    After adding node:
    <Chapters>
      <Chapter>ch1</Chapter>
      <Chapter>ch2</Chapter>
      <Chapter>ch3</Chapter>
    </Chapters>
    PL/SQL procedure successfully completed.
    SQL>

  • Generating table with XML Type column while registering schema

    Hi,
    Is it possible to generate a table with an XML Type column during schema registering. Does the "xdb:defaultTable" always create an XMLType table?
    Thanks.
    Rahul

    "You can create XML schema-based XMLType tables and columns and optionally specify, for example, that they:Conform to pre-registered XML schema ."
    http://download-east.oracle.com/docs/cd/B10501_01/appdev.920/a96620/xdb01int.htm

  • Updating xml type column

    Hi,
    I have a xml type column with content as follows
    <?xml version="1.0" encoding="utf-8"?>
    <PartInformation PartNumber="4393">
    <Maintenance />
    <Details>
    <Specs PartNumber="4393">
    <Type Code="K"></Type>
    </Specs>
    </Details>
    </PartInformation>
    <PartInformation PartNumber="4395">
    <Maintenance />
    <Details>
    <Specs PartNumber="4395">
    <Type Code="Z"></Type>
    </Specs>
    </Details>
    </PartInformation>
    I want to update the PartNumber="4393" to PartNumber="5789" for every occurrence .
    What is the easiest way to do it?
    Thanks

    Hi,
    Something like this?
    UPDATE your_table
    SET xmlcol = updatexml(xmlcol,'//*[@PartNumber="4393"]/@PartNumber','5789')
    WHERE ...

  • Insertion in XML Type table and fetching the data in Pro*C

    I have a Pro*C program written which populate one temp table. That temp table is used for writing the records to a flat file and then the table is purged by this program itself. Now my requirement is to write a new procedure in this progarm which simultaneously populate new XML Type table. Also i have to write some other procedures/functions to query the XML type table
    in Pro*C. I am new to XML part of database. Could somebody suggest how to go ahead with this problem

    Please check the Oracle Database 10g: XML DB Developer's Guild for example.

  • How to insert large xml file ino xmltype column

    Hi all,
    iam using oracle10g. I have a table example1(key_column varchar2(10),xml_column xmltype) like this. i want to insert xml file from server to xmltype column. Can you please anybody suggest regarding this.wht is the size of the xmltype column. is it same as clob like 2GB or sth different. and one more thing is iam creating one procedure in that procedure , in that we are fetching xmltype value into clob varable. is it correct or not...
    Thanks

    Manipulating a single XMLType of 2GB is probably not sensible period. I'm guessing that the content of a file that big is probably a set of smaller XML documents which someone has wrapped a begin and end tag around. Since databases are good at handling collections of documents (or collections of anything else for that matter), you should consider de-compising the large document back into a set of smaller documents before storing it in the database

  • Insert large XML files into 11g

    Can anyone post an example of inserting XML files into a XMLType table? I can use the following to insert files into a CLOB table without problems.
    $lob = oci_new_descriptor($conn, OCI_D_LOB);
              $sql = "insert into D (DATASET_ID, XML_DATA)
    values(
                   dataset_id_seq.NEXTVAL,
                   EMPTY_CLOB( )
              ) RETURNING XML_DATA into :the_blob";
              $stmt = oci_parse($conn, $sql);
              oci_bind_by_name($stmt, ':the_blob', $lob, -1, OCI_B_CLOB);
              oci_execute($stmt, OCI_DEFAULT);
              if ($lob->savefile($f)){
                   oci_commit($conn);
                   echo "Blob successfully uploaded\n";
              }else{
                   echo "Couldn't upload Blob\n";
              oci_free_descriptor($lob);
              oci_free_statement($stmt);

    A small example to insert xml file into oracle xml DB
    //$Xml contains the xml file you want to insert into the database.
    $insertXML = <<<EOF
    DECLARE xml CLOB := $Xml; begin INSERT INTO purchaseorder_as_column VALUES (1,XMLType(xml)); end;
    EOF;
    $stid = oci_parse($c, $insertXML);
    oci_execute($stid);
    //retrieve the xml data from the that table
    $sql = "select XMLTYPE.GetClobVal(xml_document) from purchaseorder_as_column where id=1";
    $stid = oci_parse($c, $sql);
    oci_execute($stid);
    $res = oci_fetch_row($stid);
    $xmldoc = $res[0]->load();
    //Then use simple xml extensions or others as you like to deal with the XML document
    $sxe = simplexml_load_string($xmldoc);
    //other operations with tthe xml data
    var_dump($sxe);

  • How to insert large xml data into database tables.

    Hi all,
    iam new to xml. i want to insert data in xml file to my database tables.but the xml file size is very large. performance is also one of the issue. can anybody please tell me the procedure to take xml file from the server and insert into my database tables.
    Thanks in advance

    Unfortunately posting very generic questions like this in the forum tends not to be very productive for you, me or the other people who read the forum. It really helps everyone if you take a little time to review existing posts and their answers before starting new threads which replicate subjects that have already been discussed extensively in previous threads. This allows you to ask more sensible questions (eg, I'm using this approach and encountering this problem) rather than extremely generic questions that you can answer yourself by spending a little time reviewing existings posts or using the forum's search feature.
    Also in future your might want to try being a little more specific before posting questions
    Eg Define "very large". I know of customers who thing very large is 100K, and customers who think 4G is medium. I cannot tell from your post what size your files are.
    What is the content of the file. Is it going to be loaded into a single record, or a a single table, or will it need to be loaded into multiple records in a single table or multiple records in multiple tables ?
    Do you really need to load the data into exsiting relational tables or could your application work with relational views of the XML Content.
    Finally which release of the database are you working with.
    Define performance. Is it reasonable to expect to process this kind of document on this machine (Make, memory, #number of CPUs, CPU Speed, number of discs) in this period of time.
    WRT to your original question. If you take a few minutes to search this forum you will find a very large number of threads with very similar titles to yours. These theads document a number of different approaches that can be used to solve this problem.
    I suggest you start by looking for threads that cover topics like DBMS_XMLSTORE, XMLTable(), Relational Views of XML content, loading XML content in relational tables.

  • ORA-22805 - (inserting an XMl type FAILS) I suspect this is a oracle Bug

    We're using
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.7.0 - Production
    Basically when I try to execute the following
    dbms_xmlschema.registerschema
    ('MySchema.xsd',
    sys.UriFactory.getUri('/Location/MySchema.xsd'),
    genTables=>TRUE);
    this generates a table for us with the name "xmlt_ds_0"
    when we try to insert into this table, we get an error
    INSERT INTO tddb.xmlt_ds_0
    SELECT sys.xmltype.createschemabasedxml(mq.content, 'http://My.Schema.xsd')
    FROM message_queue mq
    WHERE mq.sys_id = 148100
    ORA-22805: cannot insert NULL object into object tables or nested tables
    Now this works for most xml files, it just one or two that fail, however these files that have failed are well formed, and valid (ie: conform to the scehema)
    however, if I try to do this
    create table tempTest of xmltype
    XMLSCHEMA "Myschema.xsd"
    ELEMENT "schedule"
    then insert into this
    INSERT INTO tempTest
    SELECT sys.xmltype.createschemabasedxml(mq.content, 'http://My.Schema.xsd')
    FROM message_queue mq
    WHERE mq.sys_id = 148100
    Basically, this works for the same file, I just dont understand why it wouldn't work in the "resitering the schema" way. I strongly suspect this is a Oracle Bug
    Has any one encountered this before, any help would be appriciated.

    FIRST of all...
    If you create the table via registerschema, then you table will be created case-sensitive (in general take notice that with XMLDB everything can be / will be case-sensitive). So this means you will have to do things the following way (mark the double quotes):
    NSERT INTO tddb."xmlt_ds_0"
    SELECT sys.xmltype.createschemabasedxml(mq.content, 'http://My.Schema.xsd')
    FROM message_queue mq
    WHERE mq.sys_id = 148100Your statement (see below) will generate a table the default way, that is a table in uppercase
    create table tempTest of xmltype
    XMLSCHEMA "Myschema.xsd"
    ELEMENT "schedule"so ...this will create a table with the name "TEMPTEST".
    regarding the ORA-22805...
    - can you post the schema
    - can you post the values that cause the error...

  • Versioning document in XML type coloumn

    Hi All,
    I have a specific requirement in my product.I have to version the data entered in XML type coloumn. I tried searching in google and oracle 9i doc but I got the information for versioning the document stored under a partcular directory using resource_view not for my set of requiremets.
    Here I am giving more info:
    created a table abcd(int id , xmlcol XMLType)
    and associated a schema for this coloumn.Inserted data in xml format in the coloumn. I need to create different version of this data in xml type coloumn with new id.
    If any of you worked on this / have some idea abt how to proceed will be very helpful to me...
    Thanks in advance,
    Cheers
    Somasekar.

    Hi
    I am looking for some information for versioning the XMLType Column defined in the schema. The data inserted into the XML Type column will adhere to same schema.
    Can anyone help me or point me to some information.
    Thanks

  • XML-Type and reference to unavailable DTD causes validation problems

    Hi,
    I'm fairly new to Oracle's XML features. I've created a view that produces XML from a number of tables. The resulting XML is used to be stored on a web site for download by customers (this is a manual process about once a week via a CMS). It contains a reference to a DTD that is available on the web server, too. This XML must also be stored in the Oracle database. The problem is that the Oracle Server is not allowed to access any web site (Oracle server is in inhouse network with no access allowed to the world outside). So I can't store the XML in an XML-type column, as the Oracle server wants to validate the XML against the referenced DTD. There is an option not to validate the XML. But then I get the error when I try to access the XML afterwards. So up to now I use a CLOB column to store the XML, but then I lose all the benefits of an XML-type column. Is there any workaround?
    TIA,
    Stefan

    In 10.2.0.2.0 The following works
    SQL> drop table TEST_XML
      2  /
    Table dropped.
    SQL> create table TEST_XML (
      2     XML_SEQ number(10) not NULL,
      3     XML_DOC XMLType not NULL
      4  )
      5  /
    Table created.
    SQL> drop sequence TEST_XML_SEQ
      2  /
    Sequence dropped.
    SQL> create sequence TEST_XML_SEQ
      2  /
    Sequence created.
    SQL> create or replace view V_EMP_XML as select
      2         -- Processing Instruction
      3         '<?xml version="1.0" encoding="ISO-8859-1"?>' ||
      4         -- DTD reference
      5         '<!DOCTYPE employees SYSTEM "http://myserver/dtd/employees.dtd">' ||
      6         SYS.XMLTYPE.getClobVal(
      7            XMLElement("employees",
      8               (select XMLAgg(
      9                          XMLElement("emp",
    10                             XMLAttributes(
    11                                e.EMPNO as "empno",
    12                                e.DEPTNO as "deptno"
    13                             ),
    14                             XMLElement("ename", e.ENAME),
    15                             XMLElement("job", e.JOB),
    16                             XMLElement("salary", e.SAL),
    17                             XMLElement("hiredate", to_char(e.HIREDATE, 'YYYY-MM-DD'))
    18                          )
    19                       order by e.EMPNO
    20                       )
    21                from   SCOTT.EMP e
    22               )
    23            )
    24         ) as XML_DOC
    25  from   DUAL
    26  /
    View created.
    SQL>
    SQL> insert into TEST_XML
      2  (
      3    XML_SEQ,
      4    XML_DOC
      5  )
      6  select TEST_XML_SEQ.NEXTVAL,
      7         XMLType(v.XML_DOC, NULL, 1, 1)
      8  from   V_EMP_XML v
      9  /
    1 row created.
    SQL> select t.XML_DOC.getClobVal() as RESULT
      2  from   TEST_XML t
      3  where  t.XML_SEQ = 1
      4  /
    RESULT
    <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE employees SYSTEM "http://my
    SQL> select extract(t.XML_DOC, '//emp[@deptno=20]').getClobVal() as RESULT
      2  from   TEST_XML t
      3  where  t.XML_SEQ = 1
      4  /
    ERROR:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00202: could not open "http://myserver/dtd/employees.dtd" (error 101)
    Error at line 1
    no rows selected
    SQL> alter session set events ='31156 trace name context forever, level 2'
      2  /
    Session altered.
    SQL> select extract(t.XML_DOC, '//emp[@deptno=20]').getClobVal() as RESULT
      2  from   TEST_XML t
      3  where  t.XML_SEQ = 1
      4  /
    RESULT
    <emp empno="7369" deptno="20"><ename>SMITH</ename><job>CLERK</job><salary>800</s
    SQL>

Maybe you are looking for

  • Data recovery from N97 mini

    Hei all, I'm using Nokia N97 mini. Along with Phone memory and Mass memory, I inserted one 1GB memory card also. Yesterday, I was trying to copy some files in 'mass storage' mode via cable into that 1GB card. While copying, some files could not be co

  • Find hyperlinks in pdf's

    How can I find hyperlinks in pdf's? We have an external service which checks hyperlinks in our pdf's but does not tell you the location of them, so I know I may have an invalid link but can't find it. Any help at all would be appreciated

  • FM SO_NEW_DOCUMENT_ATT_SEND_API1

    Hi All I am using the FM SO_NEW_DOCUMENT_ATT_SEND_API1 in the BAdI ECM_UPDATE (Method CHANGE_BEFORE_UPDATE ) commit work inside the FM SO_NEW_DOCUMENT_ATT_SEND_API1 is causing the dump I am getting the followin dump Short text     Invalid COMMIT WORK

  • Picking the right quoattion and the value should show in PO

    Dear All, When comparing quotations the CST and VAT applicable Suppliers where VAT may be Cenvatable or Not and CST is not Cenvatable .After maintaining comparision in quotations it has to pick the right supplier quotation depending on which conditio

  • Jdeveloper 10.1.2.0 Hibernate settings

    hi i am using jdeveloper 10.1.2.0 and my application is in struts and now i wanna use Hibernate for new modules can you guys plz tell me how can i start with jdeveloper 10.1.2.0 plz note i cant change the version of jdeveloper Waiting for your reply