I have an Oracle Apex page where I receive 4 variables from the page.
:P1_COL1
:P1_COL2
:P1_COL3
:P1_COL4
The problem here is that P1_COL4 can receive many values and they are separated by a colon. So what I did was that I declared a cursor with a regexp to delimit the rows by a colon.
For example,
Currently this is what the output is if I do:
select :P1_COL1,:P1_COL2,:P1_COL3,:P1_COL4 from dual;
BOB,JONES,M,BLUE:RED:GREEN:YELLOW:PURPLE
Whereas I'm looking for something like this...
Bob, Jones, M, BLUE
Bob, Jones, M, RED
Bob, Jones, M, GREEN
Bob, Jones, M, YELLOW
Bob, Jones, M, PURPLE
But currently my code is not working
DECLARE CURSOR a1
is
WITH statement AS
(
select :P1_COL4 obj
from dual
)
SELECT REGEXP_SUBSTR(OBJ,'[^,:;]+',1,LEVEL) FROM dual CONNECT BY LEVEL<=LENGTH(REGEXP_REPLACE(OBJ,'[^,:;]+'))+1;
begin
for x in a1
loop
dbms_output.put_line(:P1_COL1 ||','|| :P1_Col2 ||','||
:P1_Col3||','|| a1 || chr(13));
end loop;
end;