sql - 快速介绍如何使用oracle xml数据类型

标签 sql xml oracle

如何使用 oracle XML 数据类型?

这个问题的目的是asked and answered由我提供,只是为了与他人分享信息

最佳答案

以下示例 SQL 演示了如何插入、查询和更新包含 XMLTYPE 数据类型的数据库字段:

-- Create a table that can store XML
create table sample_xml (id number, xml xmltype);

-- Insert some XML into the table
insert into sample_xml values (1, xmltype.createxml('<subject><name>test</name><list><li>a</li><li>b</li></list></subject>'));
insert into sample_xml values (2, xmltype.createxml('<subject><name>test</name><list><li>a</li></list></subject>'));

-- When doing a select, refer to table using the alias or getClobVal() will not work
select t.id, t.xml.getClobVal() from sample_xml t;

-- Update text of a single xml element
UPDATE sample_xml SET xml = UPDATEXML(xml, '/subject/name/text()','happy') WHERE id = 2;

-- Select out just the name for each row in the table using xpath
select id, extractvalue(xml, '/subject/name/text()') from sample_xml;

-- Doing an sample_xml, where the xpath string matches two elements, the text of both elements will be updated
UPDATE sample_xml SET xml = UPDATEXML(xml, '/subject/list/li/text()','one');

关于sql - 快速介绍如何使用oracle xml数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3975027/

相关文章:

java - ORA-01866 与 JDeveloper 10.1.3.4

sql - 从图像到 Varbinary(最大)

mysql - 字段等于零后返回默认值

sql - 从 string1 和 string2 中查找不匹配的字符

python - 如何输出 XML 实体引用

oracle - 识别预计将标志设置为 TRUE 的少数记录的最佳方法

sql - 遍历 SQL 表并执行多个查询的最快方法

java - 读取 XML 注释

java - "manifest"必须由匹配的结束标记 "</manifest>"终止

sql - 在 Oracle SQL 语句中使用分号