Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a FOR LOOP in oracle and in each loop i want to add an record to out cursor

i try

SQL
FOR reCord IN C
          LOOP      
             open cur for select reCord.TONG_TIEN as "TONG TIEN", reCord.ID_PHIEUGUI as "ID PHIEU GUI", reCord.MA_BUUCUC_GOC as "MA BC GOC" from DUAL;
          END LOOP;  


but out cur is one last row, how can i add more row using loop?
Posted

1 solution

You can't, a cursor is a read only pointer to a result set, so you're creating a new cursor (pointer to a result set) every time you open it
One way around is to use a union and create and execute it as a string like:
SQL
x := 'open cur for '
loop
    x := x || 'Select something from dual '
    x := x || 'Union all' --should not be added if it's the last row
End Loop
exec x

This is not tested or checked for syntax or other errors, it's merely for giving you an idea on a possible way to do it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900