在 DB2 脚本中将 SQL 查询结果导出为 XML
我正在尝试在要在 DB2 Linux/Unix/Windows 上运行的 SQL 脚本中查询大量系统/数据库信息。 理想情况下,输出应该是机器可读的,并且至少在某种程度上是人类可以理解的。
由于在 DB2 CLP 中格式化输出似乎不稳定(或者我太新手),我尝试将内容输出为 XML 并稍后对其进行处理,类似于:
VALUES ('<?xml version="1.0"?>');
SELECT REC2XML(1.0, 'COLATTVAL', 'row', NAME, VALUE, DEFERRED_VALUE) FROM SYSIBMADM.DBMCFG ORDER BY NAME;
This work ok;我得到的输出可能可以进一步处理。
但是,当我尝试使用 current_timestamp: 等函数运行 REC2XML 时,
SELECT Current_timestamp FROM sysibm.sysdummy1;
我无法使用 REC2XML,因为它似乎只支持列选择。
没有太多的 DB2 知识:
- 是否有更好/更简单的方法从 SQL 脚本生成 XML 输出
- 是否有某种方法也可以将 current_timestamp 等函数的结果输出为 XML?
请注意,我正在寻找 SQL 脚本(不是 shell 脚本);如果可能的话我想让它在 Windows、Linux 和 Unix 机器上可用......
I'm trying to query a lot of system/database information in an SQL script to be run on DB2 Linux/Unix/Windows.
Ideally the output should be both machine readable and at least somewhat comprehensible for humans.
As formatting the output in DB2 CLP seems erratic (or I'm too newb) I tried to output stuff as XML and process it later on, something like:
VALUES ('<?xml version="1.0"?>');
SELECT REC2XML(1.0, 'COLATTVAL', 'row', NAME, VALUE, DEFERRED_VALUE) FROM SYSIBMADM.DBMCFG ORDER BY NAME;
This works ok; I get output I can probably process further.
However, when I try to run REC2XML with a function such as current_timestamp:
SELECT Current_timestamp FROM sysibm.sysdummy1;
I can't use REC2XML as that only seems to support column selects.
Not having much DB2 knowledge:
- Is there a better/easier way to generate XML output from an SQL script
- Is there some way to also output the results of functions such as current_timestamp as XML?
Note that I'm after an SQL script (not a shell script); if possible I would like to keep it usable on Windows, Linux and Unix machines...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以获得如下函数的 XML 输出:
You can get XML output of functions like this:
DB2 for zOS 中不存在此函数。另一种方法是使用
XMLFOREST
生成列集,并使用XMLAGG
合并行。样本:
This function does not exist in DB2 for zOS. The alternate is to use
XMLFOREST
to generate a column set andXMLAGG
to merge the rows.Sample: