Skip to content
Advertisement

Repeating JSON Aggregated Array with Row Limits

I have an Oracle 19 database with a JSON aggregated array which I need to cut off and repeat after a set number of rows, for example:

…etc. Here’s some basic SQL to illustrate how my current dataset is put together:

I need to push customer data to an API endpoint. Pushing 1 customer record at a time is not performant, but the entire dataset is in the millions so cannot fit in a single array, therefore I need to, if possible, achieve the best of both worlds – 200 customer records in an array, which then ends and the next row starts a fresh array with the next 200 customers.

I have searched and found some mentions of a LIMIT function, but have not been able to successfully apply this.

Does anyone have an idea on how I can achieve this?

Advertisement

Answer

From Oracle 12, you can use ORDER BY ... OFFSET ... FETCH NEXT ... to limit the number of rows inside a sub-query:

Before Oracle 12, you can use the ROW_NUMBER analytic function:


If you want all the rows in 200 row groups then:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement