In table TEST, I want to add a column ID and fill IDs in it incremented by 1 for each row. I need the IDs sorted with respect to column COL. So far, I have done this:
ALTER TABLE TEST ADD ID INTEGER;
UPDATE TEST SET ID = ROWNUM;
The problem in this method is IDs are not sorted with respect to COL. I need something like this:
UPDATE TEST SET ID = (SELECT ROWNUM FROM TEST ORDER BY COL);
but get an error. I have also tried CTE like this:
WITH CTE AS (
SELECT * FROM TEST ORDER BY COL
) UPDATE CTE SET ROWNUM = ID;
Getting the error missing SELECT keyword.