oracle 什么是 XMLTABLE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1222570/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:41:58  来源:igfitidea点击:

What is an XMLTABLE

oracleoracle10g

提问by Sanjay Thakur

  1. What is an XMLTABLE.

  2. Do let me know the syntax of creating an XMLTABLE

  3. Sample query to fetch records from XMLTABLE.

  4. Are there any database level pre-requisites required before creating an XMLTABLE.

  1. 什么是 XMLTABLE。

  2. 请让我知道创建 XMLTABLE 的语法

  3. 从 XMLTABLE 获取记录的示例查询。

  4. 在创建 XMLTABLE 之前是否需要任何数据库级别的先决条件。

回答by Andrew Russell

The function XMLTABLEis used to translate an xml object into separated fields. But you probably want to construct a table with xml content, which is different.

函数XMLTABLE用于将 xml 对象转换为分隔的字段。但是您可能想要构造一个包含 xml 内容的表,这是不同的。

You can create a table with an extra column that contains xml content

您可以创建一个包含 xml 内容的额外列的表

CREATE TABLE mytable (my_id NUMBER PRIMARY KEY, my_xml XMLType);

Then you use the xml content inside your queries.

然后在查询中使用 xml 内容。

INSERT INTO mytable VALUES (1,xmltype('<myxml id="D45"/>'));

SELECT my_id
      ,my_xml.extract('/myxml@id').getstringval()
from mytable

Finished.

完成的。

OK responding to the second comment:

OK 回复第二条评论:

So you actually do want to use the XMLTABLE function, Your error indicates that you are not getting the file at all. So you need to craft your url to load it correctly. A test case I constructed with embedded xml is:

所以你确实想使用 XMLTABLE 函数,你的错误表明你根本没有得到文件。所以你需要制作你的 url 以正确加载它。我用嵌入式 xml 构建的一个测试用例是:

 1  SELECT seq
 2        , id
 3        , content
 4  FROM XMLTABLE('/xml/myrec'
 5        PASSING XMLType('<xml>'
 6                      ||'<myrec id="D12"><content>hello1</content></myrec>'
 7                      ||'<myrec id="D13"><content>hello2</content></myrec>
 8                      ||</xml>')
 9        COLUMNS   seq FOR ORDINALITY
10                , id VARCHAR2(100) PATH '@id'
11                , content VARCHAR2(100) PATH 'content'
12*      ) AS my_table

Output is:

输出是:

 SEQ ID    CONTENT
---- ----- --------------------
   1 D12   hello1
   2 D13   hello2

回答by Mac

XMLTABLEMight be what you'Re looking for.

XMLTABLE可能正是您要找的。