oracle 将xml转换为表格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1584731/
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
convert xml into table
提问by kobe2
I need to convert an oracle table into xml and then return it to table form.
我需要将oracle表转换为xml,然后将其返回为表格形式。
I converted a table using xmlgen, but I don't know how to reverse the conversion. I'm looking for an example of converting an xml file into a table.
我使用 xmlgen 转换了一个表,但我不知道如何反转转换。我正在寻找将 xml 文件转换为表格的示例。
回答by Sid Patel
You can create a relational view over xml table using XMLTABLE syntax.
您可以使用 XMLTABLE 语法在 xml 表上创建关系视图。
e.g. SELECT warehouse_name warehouse, warehouse2."Water", warehouse2."Rail" FROM warehouses, XMLTABLE('/Warehouse' PASSING warehouses.warehouse_spec COLUMNS "Water" varchar2(6) PATH '/Warehouse/WaterAccess', "Rail" varchar2(6) PATH '/Warehouse/RailAccess') warehouse2;
例如 SELECT 仓库名称仓库, 仓库 2."水", 仓库 2."铁路" FROM 仓库, XMLTABLE('/Warehouse' PASSING仓库.warehouse_spec COLUMNS "Water" varchar2(6) PATH '/Warehouse/WaterAccess', "Rail" varchar2( 6) PATH '/Warehouse/RailAccess') 仓库2;
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions228.htm
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions228.htm
回答by Henning
Maybe Hyperjaxb is what you need?
也许 Hyperjaxb 正是您所需要的?
It can build databse schemas from XML and vice versa and generate Object Bindings to convert between DB and XML and vice versa:
它可以从 XML 构建数据库模式,反之亦然,并生成对象绑定以在 DB 和 XML 之间进行转换,反之亦然:
https://hyperjaxb.dev.java.net/
https://hyperjaxb.dev.java.net/
回答by kurosch
Depending on what you're ultimately trying to do, a simple way is to use XMLSequence() and Table() functions in SQL to convert a nodeset from an Xpath into a rowsource:
根据您最终要执行的操作,一种简单的方法是在 SQL 中使用 XMLSequence() 和 Table() 函数将节点集从 Xpath 转换为行源:
SELECT
t.extract( '/bar/@id' ).getNumberVal() ID
FROM
TABLE( XMLSEQUENCE(
XMLTYPE(
'<foo><bar id="1" /><bar id="2" /></foo>'
).extract( '//bar' )
) ) t
回答by ftl
You can use XSLT to produce a CSV formated text.
您可以使用 XSLT 生成 CSV 格式的文本。