Click to See Complete Forum and Search --> : help inserting sequence into 5000 row table


Sureshy
03-24-2006, 07:51 AM
Hi,

I have 5000 row table. One of the columns in the table called tansactionno has no data in it.

I want to create a sequence in that column starting at 10000 and ending at 15000. So each record has a unique identifier.

i tried to create an anoynmous block using a cursor to select each record and update the transactionno with a variable, 1 is then added to the variable and the whole thing loops until 5000 records have been fetched.

Unfortunately I am not a PL/SQL expert so am failing miserably with this.

here is what I have so far.. can someone please help me correcting it. Your help is much appreciated!!!

DECLARE
x int;
CURSOR csp_val_cur is
select * from csp_temp_scy;
csp_val_rec csp_val_cur%ROWTYPE;
BEGIN
x:=10000;
OPEN csp_val_cur;
LOOP
FETCH csp_val_cur into csp_val_rec;
EXIT WHEN NOT csp_val_cur%FOUND;
update csp_temp_scy
set transactionno = x;
x:=x+1;
END LOOP;
commit;
CLOSE csp_val_cur;
end;

Sureshy
03-24-2006, 09:13 AM
Hi,

solved this by inserting the data into a temporary table and inserting a sequence into a variable that was part of the record by record insert.

would still know how it could be done with an uopdate thogh if anyone has the time.

Thanks

marist89
03-24-2006, 09:37 AM
how about UPDATE foo SET idnumber = ROWNUM + 10000

DeltaFun
03-28-2006, 10:35 AM
How about
create a sequence SEQ
and do insert
insert into table (sequenceid) values(seq.nextval);