oracle 如何在存储过程中生成 XML OutPut
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5150709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate XML OutPut in stored Procedures
提问by shyam
I will be getting few records from database using SQL query in a stored procedure , My requirement is that I need to convert these records in to XML format and send this XML as an OUT PARAM in the same stored Procedure.
我将在存储过程中使用 SQL 查询从数据库中获取少量记录,我的要求是我需要将这些记录转换为 XML 格式,并在同一个存储过程中将此 XML 作为 OUT PARAM 发送。
Can you kindly help us
你能帮助我们吗
Thanks!!
谢谢!!
回答by Jon Heller
DBMS_XMLGEN.GETXML can turn a query into XML. For example:
DBMS_XMLGEN.GETXML 可以将查询转换为 XML。例如:
select DBMS_XMLGEN.GETXML (q'!
select 1 value1, 'asdf' value2 from dual union all
select 2 value2, 'fdsa' value2 from dual
!') from dual;
Returns a CLOB with this data:
返回带有此数据的 CLOB:
<?xml version="1.0"?>
<ROWSET>
<ROW>
<VALUE1>1</VALUE1>
<VALUE2>asdf</VALUE2>
</ROW>
<ROW>
<VALUE1>2</VALUE1>
<VALUE2>fdsa</VALUE2>
</ROW>
</ROWSET>
In a stored procedure, select this into an OUT CLOB parameter.
在存储过程中,将其选择到 OUT CLOB 参数中。
回答by cagcowboy
If your requirements are more complicated than being able to use just a SQL statement as suggested by jonearles, another option is the XMLDOM package, which will allow you to create XML using PL/SQL.
如果您的需求比 jonearles 建议的只能使用 SQL 语句更复杂,另一个选项是 XMLDOM 包,它允许您使用 PL/SQL 创建 XML。
It's more complicated than DBMS_XMLGEN, but it's also more powerful.
它比 DBMS_XMLGEN 更复杂,但也更强大。