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!

Update using ROWNUM

christophelNov 24 2008 — edited Jan 20 2011
Hi,

Having the following:
create table test1 (name varchar2(10),order_id number);

insert into test1 values ('a1',1);
insert into test1 values ('a3',1.5);
insert into test1 values ('a4',2);
insert into test1 values ('a2',1.3);
commit;
I want to have only integer in order_id:
'a1',1
'a2',2
'a3',3
'a4',4
You cannot use the NAME column to sort!

I tried with no success:;
UPDATE (SELECT name, order_id 
FROM test1
ORDER BY order_id) 
SET order_id = ROWNUM;
Does not produce the expecting result because the order by is not used.

Then I tried this
UPDATE (SELECT name,order_id, rownum new_num
FROM (SELECT name, order_id 
FROM test1
ORDER BY order_id))
SET order_id = new_num;
Produce an ORA-01732 because the inline view becomes non updatable due to the virtual column ROWNUM!

Should be simple but I can't see it!?:|

Thanks

Christophe
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2011
Added on Nov 24 2008
5 comments
13,335 views