Home » SQL & PL/SQL » SQL & PL/SQL » How to convert CLOB(results of an SQL query) to XMLDocument (O/S:Windows 7 PRO; Product: Oracle; version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production)
How to convert CLOB(results of an SQL query) to XMLDocument [message #636926] Tue, 05 May 2015 19:38 Go to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
Hi,

I have a query
vStrSqlQuery := 'SELECT * FROM ' || vTblName 
                          || ' WHERE record_update_tms <= TO_DATE(''' || TO_CHAR(vLastPubTms, 'MM/DD/YYYY HH24:MI:SS') || ''', ''MM/DD/YYYY HH24:MI:SS'') ' 


Here the values being passed are runtime values where in vTblName = a table and record_update_tms = a specific date.

Based on the above, it fetches 845 rows after which I am doing the following:

vTblName                ctn_pub_cntl.table_name%TYPE;
      vLastPubTms             ctn_pub_cntl.last_pub_tms%TYPE;
      vRecordLength           NUMBER(6);
      l_clob                  CLOB;
     
      l_count                 PLS_INTEGER;
      l_nMagicNumber          NUMBER(6);
      l_xmlRowCount           NUMBER(6);
      l_nNumberofTimes        NUMBER(6);
      l_nCount                NUMBER(30);
      
      parser                  xmlparser.Parser;
      l_xmldoc                xmldom.DOMDocument;
     --parser                 Xmlparser.newParser;
     l_clob1                 CLOB;
     l_xmltype               XMLTYPE;
     l_ctx                  DBMS_XMLGEN.CTXHANDLE;
     vStrSqlQuery           VARCHAR2(32767);
   
                 
          l_ctx:=DBMS_XMLGEN.NEWCONTEXT(vStrSqlQuery);

          DBMS_XMLGEN.SETNULLHANDLING(l_ctx, 2);

          l_clob:=DBMS_XMLGEN.GETXML(l_ctx);

          --DBMS_OUTPUT.put_line(to_char(l_clob));

          -- l_xmltype:=DBMS_XMLGEN.GETXML(l_ctx);

          l_xmlRowCount:= DBMS_XMLGEN.GETNUMROWSPROCESSED(l_ctx);

          l_nCount:= DBMS_LOB.getlength(l_clob);



I am passing DBMS_XMLGEN.GETXML into l_ctx and storing the whole results of the query as a clob.

My question is, how do I convert this clob into a XMLDocument object. Any answers will be appreciated. Many thanks in advance.

[Updated on: Tue, 05 May 2015 21:54] by Moderator

Report message to a moderator

How to convert CLOB(results of an SQL query) to XMLDocument [message #636927 is a reply to message #636926] Tue, 05 May 2015 19:39 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
Hi,

I have a query
vStrSqlQuery := 'SELECT * FROM ' || vTblName 
                          || ' WHERE record_update_tms <= TO_DATE(''' || TO_CHAR(vLastPubTms, 'MM/DD/YYYY HH24:MI:SS') || ''', ''MM/DD/YYYY HH24:MI:SS'') ' 


Here the values being passed are runtime values where in vTblName = a table and record_update_tms = a specific date.

Based on the above, it fetches 845 rows after which I am doing the following:

vTblName                ctn_pub_cntl.table_name%TYPE;
      vLastPubTms             ctn_pub_cntl.last_pub_tms%TYPE;
      vRecordLength           NUMBER(6);
      l_clob                  CLOB;
     
      l_count                 PLS_INTEGER;
      l_nMagicNumber          NUMBER(6);
      l_xmlRowCount           NUMBER(6);
      l_nNumberofTimes        NUMBER(6);
      l_nCount                NUMBER(30);
      
      parser                  xmlparser.Parser;
      l_xmldoc                xmldom.DOMDocument;
     --parser                 Xmlparser.newParser;
     l_clob1                 CLOB;
     l_xmltype               XMLTYPE;
     l_ctx                  DBMS_XMLGEN.CTXHANDLE;
     vStrSqlQuery           VARCHAR2(32767);
   
                 
          l_ctx:=DBMS_XMLGEN.NEWCONTEXT(vStrSqlQuery);

          DBMS_XMLGEN.SETNULLHANDLING(l_ctx, 2);

          l_clob:=DBMS_XMLGEN.GETXML(l_ctx);

          --DBMS_OUTPUT.put_line(to_char(l_clob));

          -- l_xmltype:=DBMS_XMLGEN.GETXML(l_ctx);

          l_xmlRowCount:= DBMS_XMLGEN.GETNUMROWSPROCESSED(l_ctx);

          l_nCount:= DBMS_LOB.getlength(l_clob);



I am passing DBMS_XMLGEN.GETXML into l_ctx and storing the whole results of the query as a clob.

My question is, how do I convert this clob into a XMLDocument object. Any answers will be appreciated. Many thanks in advance.

I must add that I looked at an example which uses XMLDOM.getXMLTYPE (http://www.quest4apps.com/create-xml-using-dbms_xmldom/). However he creates a new DOM document from scratch. Is this what I am supposed to do as well? Is the approach different there than mine?

[Updated on: Tue, 05 May 2015 19:40]

Report message to a moderator

Re: How to convert CLOB(results of an SQL query) to XMLDocument [message #636928 is a reply to message #636927] Tue, 05 May 2015 19:51 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb13gen.htm#ADXDB1620
Re: How to convert CLOB(results of an SQL query) to XMLDocument [message #636929 is a reply to message #636928] Tue, 05 May 2015 19:57 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
Thanks BlakSwan. You have changed my whole question itself at least that's what it shows when I login.
Re: How to convert CLOB(results of an SQL query) to XMLDocument [message #636930 is a reply to message #636929] Tue, 05 May 2015 21:48 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
I had posted a question titled "How to convert CLOB(results of an SQL query) to XMLDocument". Someone (I presume BlackSwan, but not sure though) has changed the title of my question to "How to get the right information suggested about Date". Not sure who and why. I cannot even reply to BS as he has blocked me.

Thanks
Re: How to convert CLOB(results of an SQL query) to XMLDocument [message #636931 is a reply to message #636930] Tue, 05 May 2015 21:56 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
I am not sure how the title got changed.
I MERGED two posts by buggleboy007 into single thread since they were duplicates.

In any case I corrected the title.
Previous Topic: How to avoid showing data on each row
Next Topic: How to get the right information suggested about Date
Goto Forum:
  


Current Time: Wed May 08 21:33:03 CDT 2024