Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop through a recordset

Status
Not open for further replies.

bookouri

IS-IT--Management
Feb 23, 2000
1,464
US
I know how to do it with vb but how do i do it with Oracle pl/sql?

I have a table with about a thousand records. I want to loop through the recordset and stuff a number into a field..

is there a simple way in Oracle to do something like

id_number = 1001

while not eof
id_field = id_number
id_number = id_number + 1
loop


Im not trying to use an oracle sequence Im just trying to figure out how to loop through a recordset and update records...

thanks for any help...
 
You may loop through cursor:

declare
cursor mCur is select id_field
from your_table
for update of id_field;
id_number number;
begin

id_number = 1001;
for mVar in (mCur) loop
update your_table set id_field = id_number
where current of mCur;
id_number = id_number + 1;
end loop;

end;
 
In sem's solution, you need to use := in the assignments, not just = signs.

If you don't care what order the records get updated in, you can do this with a single UPDATE statement:

update your_table set id_field = 1001 + rownum;

Rich ____________________________
Rich Tefft
PL/SQL Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top