PLSQL (FOR LOOP) with UNION
734369May 16 2010 — edited May 17 2010I have a FOR Loop on a complex query with UNION ALL.
When I run the query below, I get results in the DBMS_OUTPUT from the query in underline, but I get not results from the the other query formed with the UNION ALL.
I cannot explain its behaviour. maybe I am doing something wrong. Is there a right way of doing this:
FOR ROWDET IN (SELECT C1,C2, C3, C4 ,C5 from (
SELECT C1, C2, C3,C4,C5 from TABLE A
UNION ALL
SELECT C1, C2, C3, C4, Test OVER (PARTITION BY TestCol order by Total desc) C5 from (
SELECT C1 C2, C3, C4 ,Test, TestCol,Total from TABLE B
)
);
LOOP
v_print_row := '<tr>';
v_print_row := v_print_row || '<td class=xl25>'|| ROWDET.C1||ROWDET.C2 || '</td>'||chr(10);
v_print_row := v_print_row||'</tr>';
DBMS_OUTPUT.PUT_LINE (v_print_row);
END LOOP;