SQL LISTAGG 合并行
LISTAGG
Syntax 语法
listagg_overflow_clause::=
Purpose
For a specified measure, LISTAGG orders data within each group specified in the ORDER BY clause and then concatenates the values of the measure column.
对于指定的度量, LISTAGG对ORDER BY 子句中指定的每个组中的数据排序,然后连接度量列的值。
• As a single-set aggregate function, LISTAGG operates on all rows and returns a single output row.
• 作为单个集合聚合函数,LISTAGG对所有行进行操作并返回单个输出行。
• As a group-set aggregate, the function operates on and returns an output row for each group defined by the GROUP BY clause.
• 作为组集聚合,函数对由group by子句定义的每个组进行操作并返回一个输出行。
• As an analytic function, LISTAGG partitions the query result set into groups based on one or more expression in the query_partition_clause.
• 作为一个分析函数,LISTAGG根据query_partition_clause中的一个或多个表达式将查询结果集划分为多个组。
The arguments to the function are subject to the following rules:
函数的参数受以下规则约束:
• The ALL keyword is optional and is provided for semantic clarity.
• ALL关键字是可选的,用于语义清晰。
• The measure_expr is the measure column and can be any expression. Null values in the measure column are ignored.
• 度量表达式是度量列,可以是任何表达式。忽略度量列中的空值。
• The delimiter designates the string that is to separate the measure column values. This clause is optional and defaults to NULL.
• 分隔符指定用于分隔度量列的字符串。此子句是可选的,默认为NULL。
If measure_expr is of type RAW, then the delimiter must be of type RAW. You can achieve this by specifying the delimiter as a character string that can be implicitly converted to RAW, or by explicitly converting the delimiter to RAW, for example, using the UTL_RAW.CAST_TO_RAW function.
如果measure_expr的类型为raw,则分隔符的类型必须为RAW。您可以通过将分隔符指定为可以隐式转换为RAW的字符串,或者通过将分隔符显式转换为RAW来实现此目的,例如,使用UTL_RAW.CAST_TO_RAW函数。
• The order_by_clause determines the order in which the concatenated values are returned. The function is deterministic only if the ORDER BY column list achieved unique ordering.
• order_by_clause确定返回连接值的顺序。仅当ORDER BY 列列表实现唯一排序时,函数才具有确定性。
If the measure column is of type RAW, then the return data type is RAW. Otherwise, the return data type is VARCHAR2.
如果度量值列的类型为RAW,则返回数据类型为RAW。否则,返回数据类型为VARCHAR2。
The maximum length of the return data type depends on the value of the MAX_STRING_SIZE initialization parameter. If MAX_STRING_SIZE = EXTENDED, then the maximum length is 32767 bytes for the VARCHAR2 and RAW data types. If MAX_STRING_SIZE = STANDARD, then the maximum length is 4000 bytes for the VARCHAR2 data type and 2000 bytes for the RAW data type. A final delimiter is not included when determining if the return value fits in the return data type.
返回数据类型的最大长度取决于MAX_STRING_SIZE初始化参数的值。如果MAX_STRING_SIZE = EXTENDED,则VARCHAR2和原始数据类型的最大长度为32767字节。如果MAX_STRING_SIZE = STANDARD,则VARCHAR2数据类型的最大长度为4000字节,原始数据类型的最大长度为2000字节。在确定返回值是否适合返回数据类型时,不包括最终分隔符。
listagg_overflow_clause
This clause controls how the function behaves when the return value exceeds themaximum length of the return data type.
此子句控制当返回值超过返回数据类型的最大长度时函数的行为。
ON OVERFLOW ERROR If you specify this clause, then the function returns anORA-01489 error. This is the default.
ON OVERFLOW ERROR 如果指定此子句,则函数返回anora-01489错误。这是默认设置。
ON OVERFLOW TRUNCATE If you specify this clause, then the function returns a truncated list of measure values.
ON OVERFLOW TRUNCATE 如果您指定了这个子句,那么函数将返回被取消标记的度量值列表。
• The truncation_indicator designates the string that is to be appended to the truncated list of measure values. If you omit this clause, then the truncation indicator is an ellipsis (...).
• truncation_indicator 指定要附加到被截断的度量值列表中的字符串。如果省略此子句,则截断指示符是省略号(…)。
If measure_expr is of type RAW, then the truncation indicator must be of type RAW. You can achieve this by specifying the truncation indicator as a character string that can be implicitly converted to RAW, or by explicitly converting the truncation indicator to RAW, for example, using the UTL_RAW.CAST_TO_RAW function.
如果measure_expr的类型为RAW,则截断指示器的类型必须为RAW。您可以通过将截断指示符指定为可以隐式转换为RAW的字符串,或者通过将截断指示符显式转换为RAW来实现这一点,例如,使用UTL_RAW.CAST_TO_RAW函数。
• If you specify WITH COUNT, then after the truncation indicator, the database appends the number of truncated values, enclosed in parentheses. In this case, the database truncates enough measure values to allow space in the return value for a final delimiter, the truncation indicator, and 24 characters for the number value enclosed in parentheses.
• 如果指定WITH COUNT,那么在截断指示符之后,数据库将附加截断值的数量,并用括号括起来。在这种情况下,数据库会截断足够的度量值,以便在返回值中为最后一个分隔符、截断指示符留出空间,并为括在括号中的数值留出24个字符。
• If you specify WITHOUT COUNT, then the database omits the number of truncated values from the return value. In this case, the database truncates enough measure values to allow space in the return value for a final delimiter and the truncation indicator.
• 如果指定WITHOUT COUNT,则数据库会从返回值中省略截断值的数量。在这种情况下,数据库截断足够的度量值,以便在返回值中为最后一个分隔符和截断指示器留出空间。
If you do not specify WITH COUNT or WITHOUT COUNT, then the default is WITH COUNT.
如果不指定WITH COUNT或WITHOUT COUNT,则默认值为WITH COUNT。
Aggregate Examples
聚合示例
The following single-set aggregate example lists all of the employees in Department 30 in the hr.employees table, ordered by hire date and last name:
以下单个集合聚合示例列出了hr.employees表中30部门中按雇用日期和姓氏排序的所有员工:
SELECT LISTAGG(last_name, '; ')
WITHIN GROUP (ORDER BY hire_date, last_name) "Emp_list",
MIN(hire_date) "Earliest"
FROM employees
WHERE department_id = 30;
Emp_list Earliest
------------------------------------------------------------ ---------
Raphaely; Khoo; Tobias; Baida; Himuro; Colmenares 07-DEC-02
The following group-set aggregate example lists, for each department ID in the hr.employees table, the employees in that department in order of their hire date:
以下组为hr.employees表中的每个部门ID按雇用日期的顺序设置聚合示例列表:
SELECT department_id "Dept.",
LISTAGG(last_name, '; ') WITHIN GROUP (ORDER BY hire_date) "Employees"
FROM employees
GROUP BY department_id
ORDER BY department_id;
Dept. Employees
------ ------------------------------------------------------------
10 Whalen
20 Hartstein; Fay
30 Raphaely; Khoo; Tobias; Baida; Himuro; Colmenares
40 Mavris
50 Kaufling; Ladwig; Rajs; Sarchand; Bell; Mallin; Weiss; Davie
s; Marlow; Bull; Everett; Fripp; Chung; Nayer; Dilly; Bissot
; Vollman; Stiles; Atkinson; Taylor; Seo; Fleaur; Matos; Pat
el; Walsh; Feeney; Dellinger; McCain; Vargas; Gates; Rogers;
Mikkilineni; Landry; Cabrio; Jones; Olson; OConnell; Sulliv
an; Mourgos; Gee; Perkins; Grant; Geoni; Philtanker; Markle
60 Austin; Hunold; Pataballa; Lorentz; Ernst
70 Baer
. . .
The following example is identical to the previous example, except it contains the ON OVERFLOW TRUNCATE clause. For the purpose of this example, assume that the maximum length of the return value is an artificially small number of 200 bytes. Because the list of employees for department 50 exceeds 200 bytes, the list is truncated and appended with a final delimiter '; ', the specified truncation indicator '...', and the number of truncated values '(23)'.
下面的示例与前面的示例相同,只是它包含ON OVERFLOW TRUNCATE子句。在本例中,假设返回值的最大长度是人为的200字节的小数字。由于部门50的员工列表超过200个字节,因此该列表将被截断并附加最后的分隔符“;”、指定的截断指示符“…”,以及截断值的数目(“23”)。
SELECT department_id "Dept.",
LISTAGG(last_name, '; ' ON OVERFLOW TRUNCATE '...')
WITHIN GROUP (ORDER BY hire_date) "Employees"
FROM employees
GROUP BY department_id
ORDER BY department_id;
Dept. Employees
------ ------------------------------------------------------------
10 Whalen
20 Hartstein; Fay
30 Raphaely; Khoo; Tobias; Baida; Himuro; Colmenares
40 Mavris
50 Kaufling; Ladwig; Rajs; Sarchand; Bell; Mallin; Weiss; Davie
s; Marlow; Bull; Everett; Fripp; Chung; Nayer; Dilly; Bissot
; Vollman; Stiles; Atkinson; Taylor; Seo; Fleaur; ... (23)
70 Baer
. . .
Analytic Example
分析示例
The following analytic example shows, for each employee hired earlier than September 1, 2003, the employee's department, hire date, and all other employees in that department also hired before September 1, 2003:
下面的分析示例显示,对于2003年9月1日之前雇用的每个员工,该员工的部门、雇用日期以及该部门中的所有其他员工也在2003年9月1日之前雇用:
SELECT department_id "Dept", hire_date "Date", last_name "Name",
LISTAGG(last_name, '; ') WITHIN GROUP (ORDER BY hire_date, last_name)
OVER (PARTITION BY department_id) as "Emp_list"
FROM employees
WHERE hire_date < '01-SEP-2003'
ORDER BY "Dept", "Date", "Name";
Dept Date Name Emp_list
----- --------- --------------- ---------------------------------------------
30 07-DEC-02 Raphaely Raphaely; Khoo
30 18-MAY-03 Khoo Raphaely; Khoo
40 07-JUN-02 Mavris Mavris
50 01-MAY-03 Kaufling Kaufling; Ladwig
50 14-JUL-03 Ladwig Kaufling; Ladwig
70 07-JUN-02 Baer Baer
90 13-JAN-01 De Haan De Haan; King
90 17-JUN-03 King De Haan; King
100 16-AUG-02 Faviet Faviet; Greenberg
100 17-AUG-02 Greenberg Faviet; Greenberg
110 07-JUN-02 Gietz Gietz; Higgins
110 07-JUN-02 Higgins Gietz; Higgins
SQL LISTAGG 合并行的更多相关文章
- SQL Server 合并行
select a.*,b.Organization_Name,c.User_Name sgry,c.renNum,d.User_Name fzr,e.pic_url from dbo.TB_ZYM_L ...
- Reapter合并行
html文件: <asp:Repeater ID="rptEmployee" runat="server"> <HeaderTemplate& ...
- Vim常用操作-合并行。
刚接触 Vim 会觉得它的学习曲线非常陡峭,要记住很多命令.所以这个系列的分享,不会教你怎么配置它,而是教你怎么快速的使用它. 在开发时为了代码美观,经常会把属性用换行的方式显示. <el-di ...
- easyui生成合并行,合计计算价格
easyui生成合并行,合计计算价格 注:本文来源: 原创 一:图样你效果图 二:代码实现 1:datagrid 列展示: window.dataGrid = $("#dataGrid&qu ...
- sed行处理详解(交换行,合并行,删除行等)
1.合并行 zj@zj:~/Script/blog_script$ cat test11234合并上下两行zj@zj:~/Script/blog_script$ sed '$!N;s/\n/\t/' ...
- 【editplus经常用的快捷键】Editplus 选中一行ctrl+r,Edit 合并行 Ctrl+Shift+J 合并选定行 删除当前行
Editplus 选中一行: ctrl+rEditplus 复制一行: ctrl+r选择行,然后ctrl+c复制.复制一行到下一行中:Editplus有:Ctrl+j 复制上一行的一个字符到当前行Ed ...
- oracle 查看并行sql语句的并行数量和如何开并行
1.执行sql:select /*+ parallel(a,4) */ * from tf_f_user a where rownum<100000; 2.如何查看该sql语句的并行数量: se ...
- SQL调优(SQL TUNING)并行查询提示(Hints)之pq_distribute的使用
pq_distribute提示通常被用于提升数据仓库中分区表间的连接操作性能. pq_distribute提示允许你确定参与连接的表数据行在生产和消费并行查询服务进程间如何分配. pq_distrib ...
- mysql 行变列(多行变成一行/多行合并成一行/多行合并成多列/合并行)
数据库结构如图: 而我想让同一个人的不同成绩变成此人在这一行不同列上显示出来,此时分为2中展现: 第一种展现如图----[多行变一列](合并后的数据在同一列上): sql如下: select name ...
随机推荐
- centos7.5系统elasticsearch使用滚动和全新安装升级到最新的elasticsearch7.4.2版本
背景: 生产环境大量使用 elasticsearch 集群,不同的业务使用不同版本的elasticsearch es经常曝出一些大的漏洞,需要进行版本升级,并且使用x-pack的基本验证功能,避免用户 ...
- 向net core 3.0进击——多平台项目发布与部署
前言 在经历过好多折腾后,总算是把部署走通了一遍,之前只是简单创建个工程在linux下部署,后来一直将这件事搁置,直到最近刚好团队入手一个小服务器,很显然是linux的,那就没啥说的了,Come On ...
- Python3基础 import...as 给导入的模块起别名
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- 【iCore4 双核心板_FPGA】实验二十:NIOS II之UART串口通信实验
实验指导书及源代码下载地址: 链接:https://pan.baidu.com/s/1g_tWYYJxh4EgiGvlfkVu1Q 提取码:dwwa 复制这段内容后打开百度网盘手机App,操作更方便哦 ...
- Java位运算符、位移运算符;原码、反码、补码
文章背景:雪花算法 id 生成长度问题. Java位运算符 - 异或运算符(^)<p>运算规则:两个数转为二进制,然后从高位开始比较,如果相同则为0,不相同则为1.</p> - ...
- js 动态加载 jq
var script=document.createElement("script"); script.type="text/javascript"; scri ...
- 百度AI身份证识别demo,使用js提交图片数据
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- 1 RAID技术入门
序 RAID一页通整理所有RAID技术.原理并配合相应RAID图解,给所有存储新人提供一个迅速学习.理解RAID技术的网上资源库,本文将持续更新,欢迎大家补充及投稿.中国存储网一如既往为广大存储界 ...
- [bug]——vue 组件状态外置引发的一个 bug
背景 在编写 .vue 组件时,可以将状态外置来获取一些额外的好处,譬如有这么一个组件(global-components.vue): <template> <div> < ...
- composer安装FOSUserBundle内存溢出
内存溢出异常: Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 4096 bytes ...