# Thread: update a null column with a sequence number

1. ## update a null column with a sequence number

So, just back from the pub after dinner........

Got a table that is populated with 500K records. Requirement is to add a new column PURN, and populate it with a sequential number starting at 12 million.

So PURN would go from 12,000,000 to 12,500,000

Can't reload table, so must update in situ....

Help!!

Not that urgent by the way........

Join Date
Sep 2002
Location
England
Posts
7,334
create sequence xxx starting with 12000000

then loop round updating ther column with next val

3. update t set new_Col = 12000000 + rownum;
select max(t) from t;

4. Thanks Guys, went for Jeff's simple rownum solution.

Old Peculiar has a way of clouding the mind......

5. Speckled Hen has a way of making you fall asleep at your desk...

6. Consider yourselves lucky. Some of us make do with lager and the occasional bottle of Newcastle Brown.

Join Date
Sep 2002
Location
England
Posts
7,334
you a geordie dapi?

8. Red Boy of Differdange
Join Date
Jan 2000
Location
Chester, England.
Posts
818
Why can't I work near a pub?

I'll have a Guinness, by the way.

9. Junior Member
Join Date
Nov 2004
Location
Mexicali.Mexico
Posts
13
Originally posted by marist89
update t set new_Col = 12000000 + rownum;
select max(t) from t;
An easiest way is:

1. Create sequence starting on 12000000.
2. Update table column in a single DML:

UPDATE t
SET x_column = t_seq.nextval;

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•