Search code examples
oracle-databasecursorlimitchunks

convert columns in rows


My general problem is that I have 10000 distinct numbers as a list of (i.e. 13, 22, 443, ..., 5010 - not in a table AND CANNOT create a table of them) and i need to loop through these numbers in chunks (1..100, 101..200, 202..300, etc. - 1st 100 number, next 100 number and so on ...)

My 1st reaction was to create a cursor and loop in it with the LIMIT clause but I am not sure if it is possible.

Is there any way to define a cursor with these specific values? If not can someone suggest me some other possibility, please?

Maybe a select all values from dual and transform them from columns into rows and from here create a cursor, is it possible?

Thank you,


Solution

  • I found this:

    cursor c is
        with test as
            (select 709941, 709959, 710165, 710183, 710199, 710201, 710203, 710220, 710352, 710571, 710630, 710710, 710714, 710723, 710724, 710761, 710845, 710877, 710878, 710892, 710908, 710915' col from dual)
                select regexp_substr(col, '[^;]+', 1, level) result
                from test
                connect by level <= length(regexp_replace(col, '[^;]+')) + 1;