Oracle: Updating a table column using ROWNUM in conjunction with ORDER BY clause

后端 未结 4 501
野的像风
野的像风 2020-12-01 12:45

I want to populate a table column with a running integer number, so I\'m thinking of using ROWNUM. However, I need to populate it based on the order of other columns, someth

4条回答
  •  情书的邮戳
    2020-12-01 13:21

    A small correction just add AS RN :

    UPDATE table_a
         SET sequence_column = (select rn 
                                 from (
                                    select rowid, 
                                          row_number() over (order by col1, col2) AS RN
                                    from table_a
                                ) x
                                where x.rowid = table_a.rowid)
    

提交回复
热议问题