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!

sequence generation using rownum and order by

999670May 30 2014 — edited May 30 2014

Hi All,

Need to generate a sequence number based on a column value in a table.

when trying to insert into a table using order by and rownum, i am not able to achieve the same.

Below is a simple example to show this .. help needed how to insert a sequence field into table base a column value ..

create table test1(col1 number);

insert into test1 values(1);

insert into test1 values(2);

insert into test1 values(4);

insert into test1 values(3);

select * from test1;

1

2

4

3

Now i try to insert into test2 based on test1 values:

create table test2(col1 number,seq number);

insert into test2 (select col1,rownum from test1  order by col1 asc);

ORA-00907: missing right parenthesis

So i tried with :

insert into test2 select col1,rownum from test1  order by col1 asc;

This worked , but the sequence is not generated as per the ordering ...

COL1SEQ

11
22
34
43

can anyone please help ..

Thanks in advance ...

MRK ...

This post has been answered by Pleiadian on May 30 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2014
Added on May 30 2014
17 comments
3,112 views