【问题标题】:How can I get multiple listagg rows for a certain number of records?如何为一定数量的记录获取多个 listagg 行?
【发布时间】:2016-02-21 18:45:58
【问题描述】:

您可能知道,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  

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

【问题讨论】:

  • 解决了!从 mytable 中选择不同的 '^.*(' || listagg(id, '|') 组内(按 id 排序)而不是(按楼层分区(rownum / 50))|| ')' 正则表达式
  • 完成,但由于一些错误,我无法重新发布 sn-p。和评论里的一样。

标签: sql oracle


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    相关资源
    最近更新 更多