Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Pagination in Oracle for the LISTAGG() function can be implemented by using the ROW_NUMBER() window function and the OFFSET and FETCH clauses.

Here's an example query for pagination with LISTAGG():

SELECT LISTAGG(col_name, ',') WITHIN GROUP (ORDER BY col_name) AS concatenated_vals
FROM (
  SELECT col_name, ROW_NUMBER() OVER (ORDER BY col_name) AS row_num
  FROM table_name
)
WHERE row_num BETWEEN :start_row AND :end_row
OFFSET :start_row FETCH NEXT :page_size ROWS ONLY;

In this query, the ROW_NUMBER() function is used to assign a unique row number to each row in the result set based on the ORDER BY clause. The WHERE clause then limits the results to only those rows with row numbers between the given start and end rows. Finally, the OFFSET and FETCH clauses are used to determine the page size and start and end rows.

Note: Replace the placeholders :startrow, :endrow, and :page_size with the actual values as per your requirement.