使用 DBMS_XMLGEN.getxml 和 Cursor 表达式时可以删除 XML 的额外嵌套吗?

发布于 2024-12-19 11:45:14 字数 676 浏览 1 评论 0原文

我一直在搜索文档和谷歌,但我似乎找不到我要找的东西;我的oracle版本是10.2.0.5。

让我们使用这个简单的查询:

select dbms_xmlgen.getxml('select cursor(select ''1'' "one", ''2''
"two", ''3'' "three" from dual) "numbers" from dual') from dual;

结果是:

"<?xml version="1.0"?>
<ROWSET>
 <ROW>
  <numbers>
   <numbers_ROW>
    <one>1</one>
    <two>2</two>
    <three>3</three>
   </numbers_ROW>
  </numbers>
 </ROW>
</ROWSET>
"

问题1:当“numbers”足够时(至少对于我的目的而言),为什么要创建“numbers_row”?

问题 2:我可以摆脱 xmlgen 包或其他包的额外嵌套吗?我使用正则表达式来做到这一点,但这似乎有点不合理。

谢谢你, -乔尔

I've been searching the documentation and google but I can't seem to find what I am looking for; my version of oracle is 10.2.0.5.

Let's use this simple query:

select dbms_xmlgen.getxml('select cursor(select ''1'' "one", ''2''
"two", ''3'' "three" from dual) "numbers" from dual') from dual;

the result is:

"<?xml version="1.0"?>
<ROWSET>
 <ROW>
  <numbers>
   <numbers_ROW>
    <one>1</one>
    <two>2</two>
    <three>3</three>
   </numbers_ROW>
  </numbers>
 </ROW>
</ROWSET>
"

Question1: Why was "numbers_row" created when "numbers" is sufficient (at least for my purposes)?

Question2: Can I get rid of that extra nesting with the xmlgen package or some other package? I'm using regular expressions to do so but it seems a bit unreasonable.

Thank you,
-joel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪梦之恋 2024-12-26 11:45:14

您需要阅读这篇文章:
http://www.orafaq.com/wiki/DBMS_XMLGEN

它解释了如何更改Oracle默认值由DBMS_XMLGEN 包生成的名称。

问题 1 的答案是:这是 Oracle DBMS_XMLGEN 包的默认值和行为

对于问题 2:您需要调用一些额外的 DBMS_XMLGEN 过程来更改默认值,因此您需要使用PL/SQL:

DECLARE
   ctx DBMS_XMLGEN.ctxHandle;
   xml CLOB;
BEGIN
   ctx := dbms_xmlgen.newcontext('select ''1'' "one", ''2'' "two", ''3'' "three" from dual');
   dbms_xmlgen.setRowTag(ctx, 'NUMBERS');
   xml := dbms_xmlgen.getxml(ctx);
   dbms_output.put_line(substr(xml,1,255));
END;

会输出:

<?xml version="1.0"?>
<ROWSET>
 <NUMBERS>
  <one>1</one>
  <two>2</two>
  <three>3</three>
 </NUMBERS>
</ROWSET>

也有一些过程可以将 值替换为更有意义的值。

希望它有帮助...

You need to read through this article:
http://www.orafaq.com/wiki/DBMS_XMLGEN

It explains how to change the Oracle default names generated by the DBMS_XMLGEN package.

The answer to your Question 1 is: it's the default values and behaviour for the Oracle DBMS_XMLGEN package

For Question 2: You would need to call some additional DBMS_XMLGEN procedures to alter the default values so you would need to use PL/SQL:

DECLARE
   ctx DBMS_XMLGEN.ctxHandle;
   xml CLOB;
BEGIN
   ctx := dbms_xmlgen.newcontext('select ''1'' "one", ''2'' "two", ''3'' "three" from dual');
   dbms_xmlgen.setRowTag(ctx, 'NUMBERS');
   xml := dbms_xmlgen.getxml(ctx);
   dbms_output.put_line(substr(xml,1,255));
END;

Would output:

<?xml version="1.0"?>
<ROWSET>
 <NUMBERS>
  <one>1</one>
  <two>2</two>
  <three>3</three>
 </NUMBERS>
</ROWSET>

There are procedures to replace the <ROWSET> value with something more meaningful too.

Hope it helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文