8

I want to know how to convert table data into xml separate file. Whether I need to use UTL file concepts?. Below is the sample code. can any one help me to clear on this?

CREATE OR PROCEDURE PRC_INSDB_XML (Booking_date1 in date)
as 

begin

SELECT XMLElement("Employee", XMLForest(empno, ename, job, mgr, hiredate, sal, comm, deptno, gender)) AS "RESULT" FROM emp where Booking_date=Booking_date1 ;

end PRC_INSDB_XML;
/

2 Answers 2

7
+25

You can generate XML using dbms_xmlgen.getxml() function.Find below link for details:

https://docs.oracle.com/cd/B10501_01/appdev.920/a96620/xdb12gen.htm#1025729

select dbms_xmlgen.getxml( 'select * from emp') as emp_xml 
from dual;

However to create an XML on your disk you need UTL package. Eg.

DECLARE
      F UTL_FILE.FILE_TYPE;
       MYCLOB CLOB;
   BEGIN
       SELECT
         DBMS_XMLGEN.GETXML('
           select deptno,dname,loc from emp
        ')
      INTO MYCLOB
      FROM DUAL;
      F := UTL_FILE.FOPEN(dest_path,'EMP.XML','w',32767);
      UTL_FILE.PUT(F,MYCLOB);
      UTL_FILE.FCLOSE(F);
  END; 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the update. I need result as a xml file in my local.
Once again thanks for your updates. I don't have privileges to create directory. If any alter way to capture xml file in folder.
If you do not have priviliges to create a directory, you should probably use the solution suggested by Andris. Your client will produce a local file.
3

If you need it on your client machine then try spooling in Sql*plus

SET HEADING OFF
SET PAGESIZE 0
SET LONG 90000
SET FEEDBACK OFF
SET ECHO OFF
SPOOL c:\downloads\file_name.xml

select dbms_xmlgen.getxml( 'select * from emp') as emp_xml 
    from dual;

SPOOL OFF

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.