聚合函数 listagg (超出长度限制时xmlagg)
表&数据
CREATE TABLE peoplebuy (people Varchar2(10),buy Varchar2(10),price NUMBER);
INSERT INTO peoplebuy VALUES ('我','小猫',10);
INSERT INTO peoplebuy VALUES ('我','小狗',200);
INSERT INTO peoplebuy VALUES ('你','树',20);
原来的结果
SELECT * FROM PEOPLEBUY ORDER BY PEOPLE;

想要的结果
SELECT PEOPLE,
LISTAGG(BUY, ',') WITHIN GROUP(ORDER BY BUY DESC) AS BUY,
SUM(PRICE) TOTAL
FROM PEOPLEBUY
GROUP BY PEOPLE
ORDER BY PEOPLE

用法

LISTAGG(measure_expr [, 'delimiter'])
WITHIN GROUP (order_by_clause) [OVER query_partition_clause]
当连接的字符串过长时会出现以下错误:

解决方案:
XMLAGGhttps://docs.oracle.com/cd/B19306_01/server.102/b14200/functions215.htm
XMLType https://docs.oracle.com/cd/B10501_01/appdev.920/a96616/arxml24.htm
RTRIM(XMLAGG(XMLELEMENT(e, t.signature_id, ',').extract('//text()')).getClobVal(),',') very_long_text
聚合元素,提取文本,获取clob,去空格
| Function | Description |
|---|---|
|
Constructor that constructs an instance of the XMLType datatype. The constructor can take in the XML as a CLOB, VARCHAR2 or take in a object type. |
|
|
Static function for creating and returning an XMLType instance. |
|
|
Takes a XMLType instance and a XPath and returns 1 or 0 indicating if applying the XPath returns a non-empty set of nodes. |
|
|
Takes a XMLType instance and an XPath, applies the XPath expression and returns the results as an XMLType. |
|
|
Checks if the input XMLType instance is a fragment or not. A fragment is a XML instance, which has more than one root element. |
|
|
Returns the value of the XMLtype instance as a CLOB |
|
|
Returns the value of the XMLtype instance as a NUMBER. This is only valid if the input XMLtpye instance contains a simple text node and is convertible to a number. |
|
|
Returns the value of the XMLType instance as a string. |
|
|
Takes an XMLtype instance and an associated stylesheet (which is also an XMLtype instance) , applies the stylesheet and returns the result as XML. |
|
|
Converts the XMLType instance to an object type. |
|
|
Returns 1 or 0 indicating if the input XMLType instance is a schema based one or not. |
|
|
Returns the XML schema URL if the input is a XMLSchema based. |
|
|
Returns the root element of the input instance. Returns NULL if the instance is a fragment |
|
|
Creates a schema based XMLtype instance from the non-schema based instance using the input schema URL. |
|
|
Creates a non schema based XML from the input schema based instance. |
|
|
Returns the namespace for the top level element in a schema based document. |
|
|
Validates the input instance according to the XMLSchema. Raises error if the input instance is non-schema based. |
|
|
Checks if the instance has been validated against the schema. |
|
|
Sets the schema valid flag to avoid costly schema validation. |
|
|
Checks if the input instance is schema valid according to the given schema URL. |
聚合函数 listagg (超出长度限制时xmlagg)的更多相关文章
- oracle 聚合函数 LISTAGG ,将多行结果合并成一行
LISTAGG( to_char(Item_Category_Name), ',') WITHIN GROUP(ORDER BY Item_Category_Name) -- 将 Item_Cate ...
- Idea如何设置代码超出长度限制时自动换行
在[File]-->[Settings]-->[Code Sytle]中勾选[Wrap on typing]选项
- 《BI项目笔记》多维数据集中度量值设计时的聚合函数
Microsoft SQL Server Analysis Services 提供了几种函数,用来针对包含在度量值组中的维度聚合度量值.默认情况下,度量值按每个维度进行求和.但是,通过 Aggrega ...
- 微软BI 之SSAS 系列 - 多维数据集中度量值设计时的聚合函数 (累加性_半累加性和非累加性)
在 SSAS 系列 - 实现第一个 Cube 以及角色扮演维度,度量值格式化和计算成员的创建 中主要是通过已存在的维度和事实数据创建了一个多维数据集,并同时解释了 Role-Playing Dimen ...
- MySQL聚合函数在计算时,不会自动匹配与之相对应的数据
学习mysql过程中遇到了一个困惑,纠结了我半天时间,刚刚又重新复习了一下,终于知道问题所在 以下是一个需求: 取得平均薪水最高的部门的部门编号 代码如下: select deptno, avg(sa ...
- SQL中子查询为聚合函数时的优化
测试数据:create table test1 as select * from dba_objects where rownum<=10000;--10000条记录create table t ...
- Oracle11g聚合函数
聚合函数就是基于多行数据返回一行结果,下面就是Oracle提供的一些列聚合函数: AVG COLLECT CORR CORR_* COUNT COVAR_POP COVAR_SAMP CUME_DIS ...
- SQL Server 聚合函数算法优化技巧
Sql server聚合函数在实际工作中应对各种需求使用的还是很广泛的,对于聚合函数的优化自然也就成为了一个重点,一个程序优化的好不好直接决定了这个程序的声明周期.Sql server聚合函数对一组值 ...
- Oracle连乘聚合函数 MUL
Oracle提供了求和(SUM),平均值(AVG)等聚合函数,但没有提供连乘的聚合函数. 比如有一个表如下: ID NUM 1 4 2 2 3 2 如果要求NUM列的连乘数,即求: 4*2*2 ,目前 ...
随机推荐
- 【linux】head&&tail
命令: head[-n][文件名] tail[-n][-f][文件名] 形式: -n 行数 (显示前几行) ...
- MySQL建表规范与常见问题 (go)
一. 表设计 库名.表名.字段名必须使用小写字母,“_”分割. 库名.表名.字段名必须不超过12个字符. 库名.表名.字段名见名知意,建议使用名词而不是动词. 建议使用InnoDB存储引擎. 存储精确 ...
- 启动zookeeper时,jps显示有进程,但是status查看状态时就Error contacting service. It is probably not running
转自:http://www.cnblogs.com/xiaohua92/p/5460515.html#undefined 安装zookeeper时候,可以查看进程启动,但是状态显示报错:Error c ...
- KMP算法解释
给定两个字符串A,B,判断T是否为S的子串(变式:寻找子串B在串A中的位置). 要求一个O(|A|+|B|)的做法. 通常称A为目标串(或主串),B为模式串. 算法过程: 我们假设串A的长度为n,串B ...
- Zookeeper客户端 CuratorFramework使用
CuratorFramework使用 跟着实例学习ZooKeeper的用法: Curator框架应用 ZooKeeper客户端Curator使用一 创建连接
- leetcode205
public class Solution { public bool IsIsomorphic(string s, string t) { if (s.Length != t.Length) { r ...
- 安装wget
今天给服务器安装新LNMP环境时,wget 时提示 -bash:wget command not found,很明显没有安装wget软件包.一般linux最小化安装时,wget不会默认被安装. 可以通 ...
- 跟我学算法- tensorflow VGG模型进行测试
我们使用的VGG模型是别人已经训练好的一个19层的参数所做的一个模型 第一步:定义卷积分部操作函数 mport scipy.io import numpy as np import os import ...
- VMware 克隆网卡无法启动
问题描述: 最近学习 hadoop,环境准备搭建在虚拟机之上,装好一台虚拟机克隆完成后,网卡无法启动. 多年前,初学 Linux 的时候,就遇到过这个问题,记录的笔记找不到了,简单记录一下. shel ...
- hive中修改序列化格式分隔符
标签: hadoophivealtertable 2014-11-19 10:45 4219人阅读 评论(0) 收藏 举报 分类: hadoop(6) 版权声明:本文为博主原创文章,未经博主允许不 ...