Oracle SQL - Add Primary Key to table

柔情痞子 提交于 2019-11-29 09:29:03
WW.
Update person set id = rownum;

THis idea is very childish, but should work fine if your table doesnot have large amount of rows.

For step 2, run a for loop like:

declare
    i pls_integer :=1;
     begin
    for rec in (select name,age, rowid from table_name)
    loop
    update table_name set id = i 
    where 
     table_name.name=rec.name 
     and table_name.age=rec.age 
     and table_name.rowid = rec.rowid;
    i:=i+1;
    end loop;
end;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!