Oralce 支持SQL XQuery查询

一个简单示例:

SELECT XMLQuery('for $i in /Videogame return $i/Type'
passing by value X
RETURNING CONTENT)
FROM (SELECT XMLTYPE('<Videogame><Type>Racing</Type><Name>NFS Most Wanted</Name><Version>2.0</Version><Size>5.5 GB</Size></Videogame>') as X
FROM dual) a;

工作实例(忽略):

select a.workflowcode,b.displayname
from
(select a.workflowcode, XMLQuery(
'for $i in /Workflow/Activities
where $i /ApproveActivity/ParticipateMethod = "Serial" and $i/ApproveActivity/ParticipateType="MultiParticipants"
return $i/ApproveActivity'
passing by value contentx
RETURNING CONTENT) XMLData
from(select a.workflowcode,a.content as contentx
from
(SELECT a.*,Row_Number() OVER (partition by a.BizObjectSchemacode ORDER BY a.workflowversion desc) versionNumb
FROM OT_WorkflowTemplatePublished a) a
where a.versionNumb=1) a
) a
left outer join Ot_Functionnode b on a.workflowcode=b.Code
where a.XMLData is not null

说明:

Note: XMLQuery returns query results as XML. XMLTable returns results as relation data.

Demo Tables

CREATE TABLE person_data (
person_id NUMBER(3),
person_data XMLTYPE);

Demo Data

INSERT INTO person_data
(person_id, person_data)
VALUES
(1, XMLTYPE('
<PDRecord>
<PDName>Daniel Morgan</PDName>
<PDDOB>12/1/1951</PDDOB>
<PDEmail>damorgan@u.washington.edu</PDEmail>
</PDRecord>')
); INSERT INTO person_data
(person_id, person_data)
VALUES
(2, XMLTYPE('
<PDRecord>
<PDName>Jack Cline</PDName>
<PDDOB>5/17/1949</PDDOB>
<PDEmail>damorgan@u.washington.edu</PDEmail>
</PDRecord>')
); INSERT INTO person_data
(person_id, person_data)
VALUES
(3, XMLTYPE('
<PDRecord>
<PDName>Caleb Small</PDName>
<PDDOB>1/1/1960</PDDOB>
<PDEmail>damorgan@u.washington.edu</PDEmail>
</PDRecord>')
); COMMIT; SELECT * FROM person_data;

SELECT

Simple Query 

语法:

SELECT <column_list>, XMLQuery (
'for $i IN <record_end_tag>
where $i<item_end_tag> = <value>
order by $i<item_end_tag>
return $i<item_end_tag>'
PASSING BY VALUE <xml_record_column>
RETURNING CONTENT) <returning_column_alias>
FROM <table_name>;
Note: What is within the parentheses is case sensitive, and you cannot use Upper Case or InitCap for commands. 示例:
(with equals)
SELECT person_id, XMLQuery(
'for $i in /PDRecord
where $i /PDName = "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data; SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName eq "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data;

(Greater Than)

SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName > "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data; SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName gt "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data;

(Greater Than Or Equal To)

SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName >= "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data; SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName ge "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data;

(Less Than)

SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName < "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data; SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName lt "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data;

(Less Than Or Equal To)

SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName >= "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data; SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName le "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data;

(Not Equals)

SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName != "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data; SELECT person_id, XMLQuery (
'for $i in /PDRecord
where $i /PDName ne "Daniel Morgan"
order by $i/PDName
return $i/PDName'
passing by value person_data
RETURNING CONTENT) XMLData
FROM person_data;

Additional Syntax Elements

[ // div union <CastAs>
- >> * intersect <CastableAs>
+ and idiv   <EOF>
| or mod   <InstanceOf>
except is to   <TreatAs>

参考:http://psoug.org/reference/xmlquery.html

Oracle XQuery 过滤XML查询SQL的更多相关文章

  1. 【ORACLE】记录通过执行Oracle的执行计划查询SQL脚本中的效率问题

    记录通过执行Oracle的执行计划查询SQL脚本中的效率问题   问题现象: STARiBOSS5.8.1R2版本中,河北对帐JOB执行时,无法生成发票对帐文件.   首先,Quartz表达式培植的启 ...

  2. SQL Server XML 查询

    [参考1] 18个小实例入门SQLServer XML查询 [参考2] 转载---SQL Server XML基础学习之<5>--XQuery(query)

  3. SQL SERVER中XML查询:FOR XML指定PATH

    SQL SERVER中XML查询:FOR XML指定PATH 前言 在SQL SERVER中,XML查询能够指定RAW,AUTO,EXPLICIT,PATH.本文用一些实例介绍SQL SERVER中指 ...

  4. ORACLE PATCH 版本的查询 PL/SQL

    --ORACLE PATCH 版本的查询 PL/SQL SELECT DD.PATCH_NAME,        PP.CREATION_DATE,        PP.DRIVER_FILE_NAM ...

  5. oracle常用查询sql

    oracle常用查询sql 原创 gordon陈 发布于2018-05-10 22:32:18 阅读数 297 收藏 展开 #!/bin/sh## create by Gordon Chen echo ...

  6. Oracle Day2 过滤、排序、单行函数

    1.过滤和排序 SQL> --查询10号部门的所有员工信息 SQL> select * from emp ; 未选定行 SQL> ed SP2: 无法创建保存文件 "afi ...

  7. oracle树形结构层级查询之start with ....connect by prior、level、order by以及sys_connect_by_path之浅谈

    浅谈oracle树状结构层级查询 oracle树状结构查询即层次递归查询,是sql语句经常用到的,在实际开发中组织结构实现及其层次化实现功能也是经常遇到的,虽然我是一个java程序开发者,我一直觉得只 ...

  8. MSCRM 2011中过滤化查询的实现方法和禁用选择视图

    MS CRM 2011中过滤化查询的实现方法 使用过滤化查询,可以实现根据表单上的其他信息作为搜索条件,限制Lookup查找框中的搜索结果数量的目的. 在讲解具体的实现方法之前,先设定一个应用场景: ...

  9. Oracle数据库的基本查询

    本文用的是Oracle 10g数据库,利用PL/SQL Developer的集成开发环境(安装可以自行百度) Oracle数据库  ---> 数据库实例  --->  表空间(逻辑单位)( ...

随机推荐

  1. 【RS】RankMBPR:Rank-Aware Mutual Bayesian Personalized Ranking for Item Recommendation - RankMBPR:基于排序感知的相互贝叶斯个性化排序的项目推荐

    [论文标题]RankMBPR:Rank-Aware Mutual Bayesian Personalized Ranking for Item Recommendation ( WAIM 2016:  ...

  2. 基于TILE-GX实现快速数据包处理框架-netlib实现分析【转】

    最近在研究suricata源码,在匹配模式的时候,有tilegx mpipe mode,转载下文,了解一下. 原文地址:http://blog.csdn.net/lhl_blog/article/de ...

  3. linux达人养成计划学习笔记(五)—— 关机和重启命令

    一.shutdown 1.格式: shutdown [选项] 时间(now) 选项: -c: 取消前一个关机命令 -h: 关机 -r: 重启 2.程序放入后台执行: shutdown -r 时间 &a ...

  4. RabbitMQ.Client API (.NET)中文文档

    主要的名称空间,接口和类 核心API中定义接口和类 RabbitMQ.Client 名称空间: 1 using RabbitMQ.Client; 核心API接口和类 IModel :表示一个AMQP ...

  5. [bug]WCF 内存入口检查失败 Memory gates checking failed

    bug描述 异常信息:内存入口检查失败,因为可用内存(xxx 字节)少于总内存的 xx%.因此,该服务不可用于传入的请求.若要解决此问题,请减少计算机上的负载,或调整 serviceHostingEn ...

  6. TFS安装配置

    安装TFS的准备工作: 1.需要安装IIS(必选): 2.需要安装SQL Server数据库(可选): 安装TFS的步骤如下: 选择左面的“基本”选项之后,点“启动向导”按钮,如下图: 进入”基本配置 ...

  7. 解决『Manifest merger failed with multiple errors, see 』

    Error:Execution failed for task ':app:processDebugManifest'.> Manifest merger failed with multipl ...

  8. MySQL执行mysql_install_db初始化

    # ./mysql_install_db \ > --defaults-file=/etc/my.cnf \ > --basedir=/data/mysql \ > --datadi ...

  9. 使用Object#tap使代码更优雅

    今天看spree源码的时候经常看到Object#tap方法.以前只知道有这个方法,而且感觉这个方法调试的作用大于实际,今日看来以前的理解应该不够准确. 先看下官方文档上tap的例子 Yields se ...

  10. 设计模式之策略模式&amp;简单工厂模式

    学习设计模式已经有非常长一段时间了,事实上先前已经敲过一遍了.可是老认为没有学到什么,认识也不够深刻.如今趁着重构机房,再又一次来过,也不晚. 事实上在敲了机房之后,看看模式,事实上,曾经非常难理解. ...