• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 70
  • Last Modified:

How to update a column with increment in Oracle

Suppose I have a table with two columns named ID, and UserName. When the table is first created ID will have all zeroes in it.
0     Barry
0     Mary
0     Jane
0     Dan

How would I update this table so that is would add 1 to each value in the ID column starting from the first record in the table. So the end result would look like below.

1    Barry
2    Mary
3    Jane
4    Dan
  • 2
1 Solution
create table yourtable (id number ,username varchar2(10));

insert into yourtable (id,username) values (0, 'Barry');
insert into yourtable (id,username) values (0, 'Mary');
insert into yourtable (id,username) values (0, 'Jane');
insert into yourtable (id,username) values (0, 'Dan');

update yourtable set id = rownum;

select * from yourtable;
brgdotnetcontractorAuthor Commented:
Sounds awesome! Thanks. I won't be able to try it until tomorrow. Thanks.
brgdotnetcontractorAuthor Commented:
Thanks !!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now