表&数据

  1. CREATE TABLE peoplebuy (people Varchar2(10),buy Varchar2(10),price NUMBER);
  2. INSERT INTO peoplebuy VALUES ('我','小猫',10);
  3. INSERT INTO peoplebuy VALUES ('我','小狗',200);
  4. INSERT INTO peoplebuy VALUES ('你','树',20);

原来的结果

  1. SELECT * FROM PEOPLEBUY ORDER BY PEOPLE;

想要的结果

  1. SELECT PEOPLE,
  2. LISTAGG(BUY, ',') WITHIN GROUP(ORDER BY BUY DESC) AS BUY,
  3. SUM(PRICE) TOTAL
  4. FROM PEOPLEBUY
  5. GROUP BY PEOPLE
  6. ORDER BY PEOPLE

用法

  1. LISTAGG(measure_expr [, 'delimiter'])
  2. 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

  1. RTRIM(XMLAGG(XMLELEMENT(e, t.signature_id, ',').extract('//text()')).getClobVal(),',') very_long_text

聚合元素,提取文本,获取clob,去空格

Function Description

XMLType()

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.

createXML()

Static function for creating and returning an XMLType instance.

existsNode()

Takes a XMLType instance and a XPath and returns 1 or 0 indicating if applying the XPath returns a non-empty set of nodes.

extract()

Takes a XMLType instance and an XPath, applies the XPath expression and returns the results as an XMLType.

isFragment()

Checks if the input XMLType instance is a fragment or not. A fragment is a XML instance, which has more than one root element.

getClobVal()

Returns the value of the XMLtype instance as a CLOB

getNumVal()

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.

getStringVal()

Returns the value of the XMLType instance as a string.

transform()

Takes an XMLtype instance and an associated stylesheet (which is also an XMLtype instance) , applies the stylesheet and returns the result as XML.

toObject()

Converts the XMLType instance to an object type.

isSchemaBased()

Returns 1 or 0 indicating if the input XMLType instance is a schema based one or not.

getSchemaURL()

Returns the XML schema URL if the input is a XMLSchema based.

getRootElement()

Returns the root element of the input instance. Returns NULL if the instance is a fragment

createSchemaBasedXML()

Creates a schema based XMLtype instance from the non-schema based instance using the input schema URL.

createNonSchemaBasedXML()

Creates a non schema based XML from the input schema based instance.

getNamespace()

Returns the namespace for the top level element in a schema based document.

schemaValidate()

Validates the input instance according to the XMLSchema. Raises error if the input instance is non-schema based.

isSchemaValidated()

Checks if the instance has been validated against the schema.

setSchemaValidated()

Sets the schema valid flag to avoid costly schema validation.

isSchemaValid()

Checks if the input instance is schema valid according to the given schema URL.

聚合函数 listagg (超出长度限制时xmlagg)的更多相关文章

  1. oracle 聚合函数 LISTAGG ,将多行结果合并成一行

    LISTAGG( to_char(Item_Category_Name), ',') WITHIN GROUP(ORDER BY Item_Category_Name)  -- 将 Item_Cate ...

  2. Idea如何设置代码超出长度限制时自动换行

    在[File]-->[Settings]-->[Code Sytle]中勾选[Wrap on typing]选项

  3. 《BI项目笔记》多维数据集中度量值设计时的聚合函数

    Microsoft SQL Server Analysis Services 提供了几种函数,用来针对包含在度量值组中的维度聚合度量值.默认情况下,度量值按每个维度进行求和.但是,通过 Aggrega ...

  4. 微软BI 之SSAS 系列 - 多维数据集中度量值设计时的聚合函数 (累加性_半累加性和非累加性)

    在 SSAS 系列 - 实现第一个 Cube 以及角色扮演维度,度量值格式化和计算成员的创建 中主要是通过已存在的维度和事实数据创建了一个多维数据集,并同时解释了 Role-Playing Dimen ...

  5. MySQL聚合函数在计算时,不会自动匹配与之相对应的数据

    学习mysql过程中遇到了一个困惑,纠结了我半天时间,刚刚又重新复习了一下,终于知道问题所在 以下是一个需求: 取得平均薪水最高的部门的部门编号 代码如下: select deptno, avg(sa ...

  6. SQL中子查询为聚合函数时的优化

    测试数据:create table test1 as select * from dba_objects where rownum<=10000;--10000条记录create table t ...

  7. Oracle11g聚合函数

    聚合函数就是基于多行数据返回一行结果,下面就是Oracle提供的一些列聚合函数: AVG COLLECT CORR CORR_* COUNT COVAR_POP COVAR_SAMP CUME_DIS ...

  8. SQL Server 聚合函数算法优化技巧

    Sql server聚合函数在实际工作中应对各种需求使用的还是很广泛的,对于聚合函数的优化自然也就成为了一个重点,一个程序优化的好不好直接决定了这个程序的声明周期.Sql server聚合函数对一组值 ...

  9. Oracle连乘聚合函数 MUL

    Oracle提供了求和(SUM),平均值(AVG)等聚合函数,但没有提供连乘的聚合函数. 比如有一个表如下: ID NUM 1 4 2 2 3 2 如果要求NUM列的连乘数,即求: 4*2*2 ,目前 ...

随机推荐

  1. 949. Largest Time for Given Digits

    Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour t ...

  2. 【转】Bash Shell中命令行选项/参数处理

    原文网址:http://www.cnblogs.com/FrankTan/archive/2010/03/01/1634516.html 0.引言 写程序的时候经常要处理命令行参数,本文描述在Bash ...

  3. Mysql 创建外键 1005 err 150

    要看错误的详细提示,可以使用命令:(在MySQL Manual里搜索“errno 150”时找到) SHOW ENGINE INNODB STATUS;     //针对用INNODB存储方式的数据库 ...

  4. redis与lua

    内容大纲 redis里使用eval和evalsha redis管理Lua脚本  php里使用redis的lua脚本 在redis里使用lua脚本的好处 1.Lua脚本在Redis中是原子执行的,执行过 ...

  5. bzoj 4069~4071 APIO2015

    T1 从高到底按位确定答案 A=1时f[i]表示前i个数合法的划分至少需要分出几段,时间复杂度$O(n^2log(ans))$ A>1时f[i][j]表示前i个数划分为j段是否可能合法,转移显然 ...

  6. Golang基础学习总结

    转自:http://blog.csdn.net/yue7603835/article/details/44264925 1.不支持继承.重载 ,比如C++.Java的接口,接口的修改会影响整个实现改接 ...

  7. Ubuntu12.10下Python(pyodbc)访问SQL Server解决方案

    一.基本原理 请查看这个网址,讲得灰常详细:http://www.jeffkit.info/2010/01/476/   二.实现步骤 1.安装linux下SQL Server的驱动程序 安装Free ...

  8. mongodb与SQL常见语句对照

    inert into users value(3,5) db.users.insert({a:3,b:5})     select a,b from users db.users.find({}, { ...

  9. linux nginx安装以及配置

    一.Nginx简介 Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...

  10. [ML] Gradient Descend Algorithm [Octave code]

    function [theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters) m = length(y); % n ...