Oracle update query to update records in sequential order

前端 未结 3 752
孤独总比滥情好
孤独总比滥情好 2021-01-28 14:06

I have a table in Oracle SQL whose ids are in increasing, sequential order, but there are gaps in the ids due to editing, e.g. the ids are currently something like



        
3条回答
  •  北海茫月
    2021-01-28 14:27

    You could use a merge, but you'd need to join on something other than emp_id as you want to update that column. If there are no other unique columns you can use the rowid:

    merge into employee target
    using (select rowid, row_number() over (order by emp_id) as emp_id from employee) source
    on (source.rowid = target.rowid)
    when matched then update set target.emp_id = source.emp_id;
    

提交回复
热议问题