2016-02-21 59 views
1

正如您所知,LISTAGG允许您将来自多行的值连接成单个值。如何为特定数量的记录获取多个listagg行?

我试图从多行构建正则表达式,然后将其提取出来以便在其他应用程序中用于搜索文件。但是,there is a limit on the maximum length of regular expressions in Oracle (512 bytes)

由于这个原因,我需要使用单独的listagg获取多行,然后导出该输出。

--The output I need is multiple rows with a listagg on 50 rows each 

select '^.*(' || listagg(id, '|') within group (order by id) || ')' regex 
from mytable 
--where rownum < 50 

这里是我卡住的地方。可能吗?

+0

解决了!选择不同的'^。*('|| listagg(id,'|')in group(order by id)over(partition by floor(rownum/50))||')'myge from mytable – Zesty

+0

done,but I由于某些错误,无法重新发布该片段。这与评论中的一样。 – Zesty

回答

1

像其他集合函数一样,listagg also supports analytic functions。所以,我们可以按价值划分它。 floor(rownum/50)为连续50行提供相同的值。

select distinct '^.*(' || listagg(id, '|') within group (order by id) 
    over (partition by floor(rownum/50)) || ')' regex 
from mytable 
相关问题