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!

Insert ROWNUM to a table column of datatype NUMBER

user13667036Jul 23 2013 — edited Jul 23 2013

Hello,

    I have a table which has a column called 'rank' of datatype NUMBER. I basically want to perform a top-n analysis and insert the ROWNUM along with other columns in the table.

TABLE1 definition:

CREATE TABLE

(

     col1     VARCHAR2(10),

     col2     NUMBER,

     col3     NUMBER,

     rank    NUMBER

);

INSERT INTO table1

SELECT col1, col2, col3, rownum

FROM (

     SELECT col1, col2, col3

     FROM table2

     ORDER BY col3 DESC

)

WHERE rownum <= 5;

I get an error, ORA-01722: invalid number. I think the error is because ROWNUM pseudocolumn is not of NUMBER datatype, so I tried to cast it like CAST(ROWNUM AS NUMBER), but it does not work, same error. Can can one please shed some light on how to convert ROWNUM to a number or if the issue is something else.

This post has been answered by user13667036 on Jul 23 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 20 2013
Added on Jul 23 2013
3 comments
8,710 views