Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how update a table with increment by 1 by using pl/sql

user580970Jun 16 2010 — edited Jun 16 2010
how update a table with increment by 1

create table pr_table(id number);

insert into pr_table values(1);
insert into pr_table values(2);
insert into pr_table values(3);
insert into pr_table values(4);
insert into pr_table values(5);
commit;

create table ch_table as select * from pr_table;


now i want update my ch_table with max id of pr_table increment by 1 for all rows. like 6 7 8 9 10


my apporach is like this

declare
v_id number;

cursor c1 is select * from ch_table;

begin

select max(id) into v_id from pr_table;

for i in c1 loop

update ch_table a set a.id = v_id +1 where a.id in(select b.id from ch_table b where a.id=b.id);

end loop;

commit;
end;

but i am geting 6 for all rows .

could you please suggest me where needs to be change my procedure to get
6 7 8 9 10

thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2010
Added on Jun 16 2010
8 comments
30,447 views