SET PAGES 0;
SET LINE 1000;
SET LONG 9999999;
SPOOL C:\pensionnew.xml;
col foo format a60000
SELECT DBMS_XMLGEN.GETXML('SELECT * FROM DATAAG')foo FROM DUAL;
SPOOL OFF;
我使用此代码生成 xml.. 答案是:假设列没有值意味着标签不会出现。为此我需要空标签
使用它的API,不要使用快速getxml(string)
版本。
例如:
SQL> variable xml clob;
SQL> declare
2 ctx number;
3 begin
4 dbms_lob.createtemporary(:xml, true, dbms_lob.call);
5 ctx := dbms_xmlgen.newcontext('select * from foo');
6 dbms_xmlgen.setnullhandling(ctx, dbms_xmlgen.EMPTY_TAG);
7 dbms_xmlgen.getxml(ctx, :xml);
8 dbms_xmlgen.closecontext(ctx);
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> print xml
XML
--------------------------------------------------------------------------------
<?xml version="1.0"?>
<ROWSET>
<ROW>
<ID>1</ID>
<A>a</A>
</ROW>
<ROW>
<ID>2</ID>
<A/>
</ROW>
</ROWSET>