Generate XML file with Customized XML tags out of oracle database table

前端 未结 1 1396
小蘑菇
小蘑菇 2021-01-14 12:03

I am working on oracle database 9ir2 I need to convert some tables into xml files with custom format tags.

for example: I want to generate XML from some columns in e

1条回答
  •  广开言路
    2021-01-14 12:19

    you do this with XMLELEMENT etc.

    select xmlelement("entity-engine-xml",
                      xmlagg(
                        xmlelement(
                          "myxmlfile", 
                          xmlattributes(empno as "EMPNO",
                                        ename as "ENAME",
                                        to_char(hiredate, 'yyyy-mm-dd') as "HIREDATE",
                                        sal as "SAL",
                                        deptno as "DEPTNO"
                                        )
                        )
                      )
                     ).getclobval()
      from emp;
    

    .

    how to convert xmltype to varchar2 ???
    

    theres a getStringVal function for this. i.e see in my example above i used getClobval. there's a getstringval() equivalent.

    EDIT: spooling:

    set trims on feedback off heading off long 50000 linesize 32767 pagesize 0
    col c format a32767
    spool c:\temp\foo.xml
    select xmlelement("entity-engine-xml",
                      xmlagg(
                        xmlelement(
                          "myxmlfile", 
                          xmlattributes(empno as "EMPNO",
                                        ename as "ENAME",
                                        to_char(hiredate, 'yyyy-mm-dd') as "HIREDATE",
                                        sal as "SAL",
                                        deptno as "DEPTNO"
                                        )
                        )
                      )
                     ).transform(xmltype('
     
     
      
       
      
     
    ')) c
      from emp;
    spool off
    

    0 讨论(0)
提交回复
热议问题