Oracle update query to update records in sequential order

前端 未结 3 756
孤独总比滥情好
孤独总比滥情好 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:28

    This solution to the same question you referenced shows how to do it:

    update employee set emp_id = (
      with tab as (
        select emp_id, rownum r
        from   (select emp_id from employee order by emp_id)
      )
      select r from tab where employee.emp_id = tab.emp_id
    );
    

    That works. You cannot update a view that contains an analytic function like row_number - see Oracle 12C docs, look for "Notes on Updatable Views".

提交回复
热议问题