KingbaseES 与 Oracle XML 语法比较
KingbaseES 内置支持 XML 相关操作,也可以通过xml2 插件进行扩展支持。以下通过例子介绍 KingbaseES XML 与Oracle 在用法上存在的一些差异。
一、数据准备
create table t1(content xml);
insert into t1 values( xml ('<Employees>
<Employee emplid="1111" type="admin">
<firstname>John</firstname>
<lastname>Watson</lastname>
<age>30</age>
<email>johnwatson@sh.com</email>
</Employee>
<Employee emplid="2222" type="admin">
<firstname>Sherlock</firstname>
<lastname>Homes</lastname>
<age>32</age>
<email>sherlock@sh.com</email>
</Employee>
<Employee emplid="3333" type="user">
<firstname>Jim</firstname>
<lastname>Moriarty</lastname>
<age>52</age>
<email>jim@sh.com</email>
</Employee>
<Employee emplid="4444" type="user">
<firstname>Mycroft</firstname>
<lastname>Holmes</lastname>
<age>41</age>
<email>mycroft@sh.com</email>
</Employee>
</Employees>') );
二、XML节点标记方式
|
Expression |
Description |
|
nodename |
选择所有名称为"nodename"的节点 |
|
/ |
选择根节点 |
|
// |
从当前节点选择文档中相匹配的节点,无论他们在哪里 |
|
. |
选择当前节点 |
|
.. |
选择当前节点的父节点 |
|
@ |
选择属性 |
|
employee |
选择所有名称为"employee"的节点 |
|
employees/employee |
选择所有子节点为employee的employees节点 |
|
//employee |
选择所有employee的元素,无论他们在哪里 |
|
Path Expression |
Result |
|
/employees/employee[1] |
选择第一个employee节点,它是employees的子节点。 |
|
/employees/employee[last()] |
选择最后一个employee元素,它是employees的子节点 |
|
/employees/employee[last()-1] |
选择是employees子元素的倒数第二个employee元素 |
|
//employee[@type='admin'] |
选择所有具有与'admin'的值的属性命名类型的employee元素 |
三、Extract
1、Oracle
SQL> select extract(content,'/Employees/Employee/firstname') from t1; EXTRACT(CONTENT,'/EMPLOYEES/EMPLOYEE/FIRSTNAME')
--------------------------------------------------------------------------------
<firstname>John</firstname>
<firstname>Sherlock</firstname>
<firstname>Jim</firstname>
<firstname>Mycroft</firstname>
2、KingbaseES
test=# select extract(content,'/Employees/Employee/firstname') from t1;
extract
--------------------------------------------------------------------------------------------------------------------
<firstname>John</firstname><firstname>Sherlock</firstname><firstname>Jim</firstname><firstname>Mycroft</firstname>
(1 row)
四、Xpath
XPath使用路径表达式来选择XML文档中的节点或节点列表。Oracle 没有该函数。
使用例子:
test=# select xpath('/Employees/Employee/firstname',content) from t1;
xpath
-------------------------------------------------------------------------------------------------------------------------
{<firstname>John</firstname>,<firstname>Sherlock</firstname>,<firstname>Jim</firstname>,<firstname>Mycroft</firstname>}
(1 row)
test=# select xpath('/Employees/Employee/firstname/text()',content) from t1;
xpath
-----------------------------
{John,Sherlock,Jim,Mycroft}
(1 row)
五、XMLTable
KingbaseES 有XMLTable 函数,Oracle 用 TABLE + XMLSequence 实现。
1、KingbaseES
test=# select c from t1,xmltable('/Employees/Employee/firstname' passing t1.content columns c xml path '.');
c
---------------------------------
<firstname>John</firstname>
<firstname>Sherlock</firstname>
<firstname>Jim</firstname>
<firstname>Mycroft</firstname>
(4 rows)
2、Oracle
select value(T) AS C from TABLE(XMLSequence(extract(XMLTYPE('<Employees>
<Employee emplid="1111" type="admin">
<firstname>John</firstname>
<lastname>Watson</lastname>
<age>30</age>
<email>johnwatson@sh.com</email>
</Employee>
<Employee emplid="2222" type="admin">
<firstname>Sherlock</firstname>
<lastname>Homes</lastname>
<age>32</age>
<email>sherlock@sh.com</email>
</Employee>
<Employee emplid="3333" type="user">
<firstname>Jim</firstname>
<lastname>Moriarty</lastname>
<age>52</age>
<email>jim@sh.com</email>
</Employee>
<Employee emplid="4444" type="user">
<firstname>Mycroft</firstname>
<lastname>Holmes</lastname>
<age>41</age>
<email>mycroft@sh.com</email>
</Employee>
</Employees>'),'/Employees/Employee/firstname'))) T;
C
--------------------------------------------------------------------------------
<firstname>John</firstname>
<firstname>Sherlock</firstname>
<firstname>Jim</firstname>
<firstname>Mycroft</firstname>
KingbaseES 与 Oracle XML 语法比较的更多相关文章
- Oracle存储过程语法
原文链接:http://www.jb51.net/article/31805.htm Oracle存储过程基本语法 存储过程 1 CREATE OR REPLACE PROCEDURE 存储过程名 ...
- [SQL] Oracle基础语法
1.安装: oracle11g server 这里的口令为sys和system的密码.(10版本以前默认用户会有系统默认密码.) Oracle 11g 默认用户名和密码 oracle11g clien ...
- xml语法、DTD约束xml、Schema约束xml、DOM解析xml
今日大纲 1.什么是xml.xml的作用 2.xml的语法 3.DTD约束xml 4.Schema约束xml 5.DOM解析xml 1.什么是xml.xml的作用 1.1.xml介绍 在前面学习的ht ...
- ORACLE基本语法
ORACLE基本语法 一.ORACLE的启动和关闭1.在单机环境下要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下su - oraclea.启动ORACLE系统oracle>s ...
- 【风马一族_xml】xml语法
xml语法 文档声明 用来声明xml的属性,用来指挥解析引擎如何去解析当前xml 通常一个xml都要包含并且只能包含一个文档声明 xml的文档必须在整个xml的最前面,在文档声明之前不能有任何内容 & ...
- How to Determine the Version of Oracle XML Publisher for Oracle E-Business Suite 11i and Release 12 (Doc ID 362496.1)
Modified: 29-Mar-2014 Type: HOWTO In this DocumentGoal Solution 1. Based upon an output file gen ...
- 安装oracle XML Database 组件
近期部署项目数据库,编译包时遇到错误: PACKAGE CTG.CTG_CSB_COMMON 编译错误 错误:PLS-00201: identifier 'XMLDOM' must be dec ...
- XML 语法规则
转摘自:http://www.w3school.com.cn/xml/xml_elements.asp XML 语法规则 XML 文档包含 XML 元素. XML 的语法规则很简单,且很有逻辑.这些规 ...
- [SQLXML]FOR XML语法导出XML的易错之处
原文:[SQLXML]FOR XML语法导出XML的易错之处 [SQLXML]FOR XML语法导出XML的易错之处 Version Date Creator Description 1.0.0.1 ...
- 利用XML语法 SQL 列转行
--行转列 固定xml语法 declare @xml xml ; set @xml=cast('<v>2</v><v>4</v><v>3&l ...
随机推荐
- ffmpeg之avformat_alloc_output_context2
函数原型: int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const ...
- redis大key分析工具redis-rdb-tools
最近1台云Redis的内存曝高,24G的内存占用19G,而且一直增长,想看那些key比较大,腾讯云Redis有大key分析的结果,但是这台没有,估计要找腾讯云的技术刷新一下数据: 分析大key工具,有 ...
- Springboot集成Druid连接池并实现数据库密码加密
Druid介绍 Druid首先是一个数据库连接池.Druid是目前最好的数据库连接池,在功能.性能.扩展性方面,都超过其他数据库连接池,包括DBCP.C3P0.BoneCP.Proxool.JBoss ...
- SpringCloud服务注册与发现Eureka实战
介绍 Spring Cloud 封装了 Netflix 公司开发的 Eureka 模块来实现服务治理在传统的rpc远程调用框架中,管理每个服务与服务之间依赖关系比较复杂,管理比较复杂,所以需要使用服务 ...
- bootstrap与javascript
1.bootstrap依赖 bootstrap依赖javascript类库,jQuery 下载jQuery,在页面上应用jQuery 在页面上应用bootstrap的js类库 <script s ...
- 2021-10-25 css中零值0后面是否要省略单位
原理 在css中如果值为0,可以省略单位. 在css应用场景中,有可能是多端多人维护.即可能维护的人有A及B及C-,应用场景中有电脑端及手机端及小程序及打印机之类的. 结论 个人认为不要省略单位,不要 ...
- EXE程序缺DLL怎么办
起因 工程师发给用户一个VS编译的windows应用程序,客户反应打不开,报缺少dll.可是dll明明就在当前目录啊,为什么还会报错呢? 那应该是该DLL依赖的其它DLL不存在导致的,用depends ...
- 关于无法查看hadoop的防火墙状态解决方法
可以参考这两位博主写的 https://www.055401.com/computer/376.html https://blog.csdn.net/weixin_52596632/article/d ...
- 【对比】Gemini:听说GPT-4你小子挺厉害
前言 缘由 谷歌连放大招:Gemini Pro支持中文,Bard学会画画 事情起因: 一心只读圣贤书的狗哥,不经意间被新闻吸引.[谷歌最新人工智能模型Gemini Pro已在欧洲上市 将与ChatGP ...
- 《Document-level Relation Extraction as Semantic Segmentation》论文阅读笔记
原文 代码 摘要 本文研究的是文档级关系抽取,即从文档中抽取出多个实体之间的关系.现有的方法主要是基于图或基于Transformer的模型,它们只考虑实体自身的信息,而忽略了关系三元组之间的全局信息. ...