If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL Update

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-03, 13:22
sudha_sql sudha_sql is offline
Registered User
 
Join Date: Oct 2003
Posts: 1
SQL Update

I have a table called Table1:

Fields and values:

id text number
1 a
2 b
1 c

All I want to do is to update the above table, so that the number is set as 1,2,3 i.e, incremented by 1;Hence the resultant table will look as:

id text number
1 a 1
2 b 2
1 c 3

Can you please help me to write an update statement?

Thanks
Reply With Quote
  #2 (permalink)  
Old 10-21-03, 15:36
Lazy Lazy is offline
Registered User
 
Join Date: Sep 2003
Location: Brussel
Posts: 52
If I understand you well, you need a sequence:

CREATE SEQUENCE [sequence name]
INCREMENT BY 1
START WITH [where do you wanna start?]
MAXVALUE [an integer, can also be NOMAXVALUE]
MINVALUE [an integer, can also be NOMINVALUE]
CYCLE (or NOCYCLE)
__________________
A good programmer is a LAZY programmer!
Reply With Quote
  #3 (permalink)  
Old 10-21-03, 15:42
Lazy Lazy is offline
Registered User
 
Join Date: Sep 2003
Location: Brussel
Posts: 52
Forgot the update statement

UPDATE [table] SET number = [sequence].nextval;

I tried it on a little test table I created, so I guess it should work for you. My test:

SQL> create table test(a number(2),b varchar2(3),c number(2));

Tabel is aangemaakt.

SQL> insert into test values (1, 'a', null);

1 rij is aangemaakt.

SQL> insert into test values (2, 'b', null);

1 rij is aangemaakt.

SQL> insert into test values(1, 'c', null);

1 rij is aangemaakt.

SQL> create sequence tt
2 increment by 1
3 start with 1;

Reeks is aangemaakt.

SQL> select * from test;

A B C
---------- --- ----------
1 a
2 b
1 c

SQL> update test set c = tt.nextval;

3 rijen zijn bijgewerkt.

SQL> select * from test;

A B C
---------- --- ----------
1 a 1
2 b 2
1 c 3

3 rijen zijn bijgewerkt = 3 rows updated I work with a dutch version
__________________
A good programmer is a LAZY programmer!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On