Oracle
 SQL >> Datenbank >  >> RDS >> Oracle

Eine Cursor-FOR-Schleife mit einer Cursor-Variablen in Oracle verwenden

Um die Probleme mit dem zweiten Ansatz in Ihrer Frage zu adressieren, brauchen Sie eine Cursor-Variable zusammen mit einem expliziten Open-and-Fetch-Muster. Cursor-Variablen sind in der FOR-Schleife nicht erlaubt:

declare l_sql varchar2(123); -- variable that contains a query l_c sys_refcursor; -- cursor variable(weak cursor). l_res your_table%rowtype; -- variable containing fetching data begin l_sql := 'select * from your_table'; -- Open the cursor and fetching data explicitly -- in the LOOP. open l_c for l_sql; loop fetch l_c into l_res; exit when l_c%notfound; -- Exit the loop if there is nothing to fetch. -- process fetched data end loop; close l_c; -- close the cursor end;

Mehr erfahren