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

后端 未结 4 495
野的像风
野的像风 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:13

    First Create a sequence :

    CREATE SEQUENCE SEQ_SLNO
      START WITH 1
      MAXVALUE 999999999999999999999999999
      MINVALUE 1
      NOCYCLE
      NOCACHE
      NOORDER;
    

    after that Update the table using the sequence:

    UPDATE table_name
    SET colun_name = SEQ_SLNO.NEXTVAL;
    

提交回复
热议问题