[英]LISTAGG query in Oracle split in batches
I want to get a list of tables group by Schema and split the list of tables in batches, in Oracle Database (19.3).我想在 Oracle 数据库 (19.3) 中获取按模式分组的表列表并批量拆分表列表。
Example: I have 10 tables (A,B,C,D,E,F,G,H,I,J) which belong to HR schema.示例:我有 10 个表(A、B、C、D、E、F、G、H、I、J)属于 HR 模式。 with the query that I have I get this output
Select Schema, LISTAGG(Table_Name) FROM SchemaInfo GROUP BY Schema
通过查询,我得到了这个输出
Select Schema, LISTAGG(Table_Name) FROM SchemaInfo GROUP BY Schema
Schema![]() |
Tables![]() |
---|---|
HR![]() |
A,B,C,D,E,F,G,H,I,J ![]() |
I would like split the group in batches of 5 elements and get an ouptput like this:我想将组分成 5 个元素的批次并获得如下输出:
Schema![]() |
Tables![]() |
---|---|
HR![]() |
A,B,C,D,E![]() |
HR![]() |
F,G,H,I,J ![]() |
Are there any way to get this output?有什么办法可以得到这个输出吗? I have something similar for SQL but in Oracle is not working the same approach.
我对 SQL 有类似的东西,但在 Oracle 中使用的方法不同。
There's probably an easier way, but here's an example I did with all_tables
:可能有一种更简单的方法,但这是我用
all_tables
做的一个例子:
select owner, listagg(table_name, ',')
from (
select owner, table_name, floor(row_number() over (partition by owner order by table_name)/5) as batch
from all_tables)
group by owner, batch
order by owner, batch
With your table, it would look like:使用您的表,它看起来像:
select Schema, listagg(table_name, ',') as Tables
from (
select Schema, table_name, floor(row_number() over (partition by Schema order by table_name)/5) as batch
from SchemaInfo)
group by Schema, batch
order by Schema, batch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.