在 PL/SQL 中将集合包装为 XMLTYPE (Oracle)
Wrap collection to XMLTYPE in PL/SQL (Oracle)
聪明的家伙!
假设我有一个 table:
id NUMBER name VARCHAR2 info XMLTYPE
--
1 Brad <?xml version="1.0" encoding="ISO-8859-5"?>
2 Angelina <?xml version="1.0" encoding="ISO-8859-5"?>
在我的包中我可以select它到一些集合变量v_table.
我需要将其转换为 XML 和 return XMLTYPE,如下所示:
<?xml version="1.0" encoding="ISO-8859-5"?>
<rows>
<row>
<id type="NUMBER">1</id>
<name type="VARCHAR2">Brad</name>
<info type="XMLTYPE"><!-- somehow insert here xml, maybe base64 encoded --></info>
</row>
<row>
<id type="NUMBER">2</id>
<name type="VARCHAR2">Angelina</name>
<info type="XMLTYPE"><!-- somehow insert here xml, maybe base64 encoded --></info>
</row>
</rows>
所以我需要制作一些通用函数来将任何集合转换为 XML。不幸的是,我不知道 PL/SQL(只知道 MySQL,MsSQL),我只是不知道正确的开始方式。你能给我一些建议吗?
PS: "type" 属性不是必需的,但会很酷。
谢谢,乔恩·海勒!
The package DBMS_XMLGEN already does that. For example: select dbms_xmlgen.getxml('select * from dual') from dual;. Then you could perhaps apply a stylesheet to the results through the XMLType function TRANSFORM.
聪明的家伙!
假设我有一个 table:
id NUMBER name VARCHAR2 info XMLTYPE
--
1 Brad <?xml version="1.0" encoding="ISO-8859-5"?>
2 Angelina <?xml version="1.0" encoding="ISO-8859-5"?>
在我的包中我可以select它到一些集合变量v_table.
我需要将其转换为 XML 和 return XMLTYPE,如下所示:
<?xml version="1.0" encoding="ISO-8859-5"?>
<rows>
<row>
<id type="NUMBER">1</id>
<name type="VARCHAR2">Brad</name>
<info type="XMLTYPE"><!-- somehow insert here xml, maybe base64 encoded --></info>
</row>
<row>
<id type="NUMBER">2</id>
<name type="VARCHAR2">Angelina</name>
<info type="XMLTYPE"><!-- somehow insert here xml, maybe base64 encoded --></info>
</row>
</rows>
所以我需要制作一些通用函数来将任何集合转换为 XML。不幸的是,我不知道 PL/SQL(只知道 MySQL,MsSQL),我只是不知道正确的开始方式。你能给我一些建议吗?
PS: "type" 属性不是必需的,但会很酷。
谢谢,乔恩·海勒!
The package DBMS_XMLGEN already does that. For example: select dbms_xmlgen.getxml('select * from dual') from dual;. Then you could perhaps apply a stylesheet to the results through the XMLType function TRANSFORM.