generate XML doc using DBMS_XMLGEN and write it to a file system [message #91634] |
Wed, 18 December 2002 18:51 |
Devang Pandya
Messages: 9 Registered: June 2002
|
Junior Member |
|
|
Hi Friends,
I'm facing a big trouble for writting a XML doc generated by the DBMS_GENXML.getXML function (it retunrs xml doc as CLOB datatype) to the file system. I can not use utl_file because it does not support CLOB(i guess..I'm not sure abt that). I'm trying to convert that CLOB to varchar2 and then write it to file using utl_file pkg but it is giving me problem. Can some one give me the solution for this?
var my_xml clob
set autoprint on
declare
l_clob clob;
l_ctx dbms_xmlgen.ctxHandle;
l_sql varchar2(400);
flag boolean ;
begin
l_sql := 'select * from MESSAGE_TEMPLATE where rownum < 5';
l_ctx := dbms_xmlgen.newContext(l_sql);
:my_xml := dbms_xmlgen.getXml(l_ctx); -- or you could assign it to l_clob
end;
The above block give me perfect output on sqlplus but i want to write that output to some file.
Please Help !!!
thanks in advance
|
|
|
|
|
|
Re: generate XML doc using DBMS_XMLGEN and write it to a file system [message #92531 is a reply to message #91634] |
Wed, 01 September 2004 23:58 |
Kumar
Messages: 115 Registered: December 1998
|
Senior Member |
|
|
l_clob_len := DBMS_LOB.GETLENGTH(my_xml );
l_amount := 32767;
l_pos := 1;
-------------------------------------------------------------------
--Copy the contents of the CLOB to the File
--
-------------------------------------------------------------------
WHILE l_pos < l_clob_len
LOOP
DBMS_LOB.READ(l_xml_clob, l_amount, l_pos, l_Buffer);
IF l_Buffer IS NOT NULL THEN
-- write it to the File
UTL_FILE.PUT( l_handle, l_Buffer );
END IF;
l_pos := l_pos + l_amount;
END LOOP;
UTL_FILE.FCLOSE(l_handle);
DBMS_LOB.FREETEMPORARY(l_xml_clob);
|
|
|