Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: PL/SQL Questions.
It works perfectly. What you are doing is:
x=1
set testid=1 for ALL rows in the users table
print out x (which is 1)
x=2
set testid=2 for ALL rows in the users table
print out x (which is 2)
x=3
set testid=3 for ALL rows in the users table
print out x (which is 3)
So now ALL the rows in the user table for testid are = to 3.
So
Select testid from users returns
3
3
3
which is correct.
I think what you are trying to do is set testid to 1 in the "first" row, 2 in the "second" row and 3 in the "third" row. To do that just do:
update users set testid=rownum;
Jim
"Anthony Scott" <ascott_at_interaccess.com> wrote in message
news:3B643DB5.E34DD940_at_interaccess.com...
> Can anyone tell me why the following code doesn't produce the desire
> results?
>
>
> BEGIN
> FOR x IN 1..3 LOOP
> update users set testid = x;
> DBMS_OUTPUT.PUT_LINE(x);
> END LOOP;
> END;
>
> output to sqlplus is : 1
> 2
> 3
>
> output in testid is : 3
> 3
> 3
>
>
>
> RH 6.1
> Oracle 8.1.6
>
> Tony
>
Received on Sun Jul 29 2001 - 11:57:25 CDT
![]() |
![]() |