I want to update a table column with row number.
Each row in empid
column should update with related row number.
I tried following query.
UPDATE employee SET empid = row_number();
But this is not working. Any idea?
I want to update a table column with row number.
Each row in empid
column should update with related row number.
I tried following query.
UPDATE employee SET empid = row_number();
But this is not working. Any idea?
you could also do this
this creates the serial number when you write the table itself. ( note this is not set as PK if you want it to act as pk)
You could do something like the following. You can change the ORDER BY order the rows if needed.
Firstly, it is syntactically incorrect.
Secondly, you cannot use
ROW_NUMBER()
analytic function without the analytic_clause.As you replied to my comment that the order doesn't matter to you, you could simply use ROWNUM.
It will assign the pseudo-column value by randomly picking the rows. Since you are assigning EMPID, I would suggest you should consider ordering.
Usually employee ids are generated using a SEQUENCE object. There are two ways to implement the auto-increment functionality:
First, this is not the correct syntax for the
row_number()
function, since you're missing theover
clause (resulting in an ORA-30484 error). Even if it was, this would not work, as you cannot directly use window functions in aset
clause (resulting in an ORA-30483 error).For this usecase, however, you could just use the
rownum
pseudo-column:SQLFiddle