将 Oracle 行序列化为 XML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/491838/
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
Serialize Oracle row to XML
提问by Osama Al-Maadeed
I want to create a stored procedure that takes the name of a table and a row_id and can serialize it to an xml string.
我想创建一个存储过程,它采用表的名称和 row_id 并将其序列化为 xml 字符串。
The table may contain clobs and blobs.
该表可能包含 clob 和 blob。
Can I do this in PL/SQL, or do I have to use Java?
我可以在 PL/SQL 中执行此操作,还是必须使用 Java?
The main objective for this is to have a table with all updates and deletes on some tables, keeping the X latest versions, or X days of Data (the table would include something like chg_date(default:sysdate)
, chg_type(U or D)
, chg_xml
, and probably with some metadata about the user).
这样做的主要目标是拥有一个包含某些表上所有更新和删除的表,保留 X 最新版本或 X 天的数据(该表将包含诸如chg_date(default:sysdate)
, chg_type(U or D)
, 之类的内容chg_xml
,并且可能包含一些有关用户的元数据)。
Possible uses: - It could also keep all the data and be used as a log - The ability to return the row to any previous value. - The ability to do EDI in a specific format.
可能的用途: - 它还可以保留所有数据并用作日志 - 将行返回到任何先前值的能力。- 以特定格式进行 EDI 的能力。
I don't want to use Oracle's flashback queries to get there since there's no guarantee of the data availability.
我不想使用 Oracle 的闪回查询到达那里,因为无法保证数据可用性。
采纳答案by Daniel Emge
Oracle has a function to return a query in xml format.
Oracle 具有以 xml 格式返回查询的功能。
In this example, replace &table with your table name, and &rowid with the rowid. I tested it and it seems to work with clobs and blobs. For blobs it returns the data in hex.
在此示例中,将 &table 替换为您的表名,并将 &rowid 替换为 rowid。我测试了它,它似乎适用于 clobs 和 blob。对于 blob,它以十六进制返回数据。
SELECT DBMS_XMLGEN.getxmltype ('select * from &table_name where rowid = ''&rowid''' )
FROM DUAL