2016-02-21 60 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 
相關問題