sql - 甲骨文11g : XQuery results concatenated in a single SQLXML type

标签 sql oracle xquery xmltype xmltable

当我使用 PL-SQL 运行 XQuery 查询时

 SELECT XQUERY('...' RETURNING CONTENT) FROM DUAL

结果始终以包含 SQLXML 字段的单行单列串联形式返回。

这对于返回元素序列的查询来说是不好的,对于返回文本节点序列的查询来说确实很糟糕。

有没有办法避免这种串联并为每个返回的项目获取一行?

谢谢

埃里克

最佳答案

您想使用XMLTable而不是 XQuery。

XMLTable maps the result of an XQuery evaluation into relational rows and columns. You can query the result returned by the function as a virtual relational table using SQL.

例如:

create table customer as
select 1 id, 'Smith'   last_name from dual union all
select 2 id, 'Jackson' last_name from dual union all
select 3 id, 'Peters'  last_name from dual;

SELECT * from XMLTable('
    for $customer in ora:view("customer")/ROW
       return $customer/LAST_NAME'
     columns "last_name" varchar2(4000) path '/LAST_NAME');

last_name
---------
Smith
Jackson
Peters

关于sql - 甲骨文11g : XQuery results concatenated in a single SQLXML type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10663351/

相关文章:

oracle - 检查约束可以与另一个表相关吗?甲骨文

json - JSONiq 和 XQuery 3.1 之间有什么区别?

php - 数据库设计: How to record bundle product deliveries

java - Oracle BLOB(使用 Base 64 编码)到字符串

php - Mysql中重复行的条目

oracle - API 蓝图在实时 API 上因 dredd 失败?

xml - 如何通过 XQuery 从 XML 中获取所有元素

java - 解析 XML 文件获取所有 Namespace 信息

mysql - 将负值插入mysql数据库?

mysql - 更新集 = 选择语句 & 主键问题