Stanley Mungai
Stanley Mungai

Reputation: 4150

update a column with sequential Values

Hi Guys I have a table with Multiple column and rows my First Column B2kID is blank I need it Update with values Like:

VC1
VC2
VC3
VC4
 .
 .

How can I achieve this?

Upvotes: 0

Views: 1612

Answers (3)

Xavi López
Xavi López

Reputation: 27880

You could use the rownum pseudocolumn to get a unique identifier for each of the affected rows, and just use it along with the || concatenation operator in a regular UPDATE sentence:

UPDATE myTable SET B2kID = 'VC' || rownum;

Here is a sample SQLFiddle.

Upvotes: 3

Vignesh Ravichandran
Vignesh Ravichandran

Reputation: 31

The PL/SQL block provided in the following link can be useful. http://searchoracle.techtarget.com/answer/Creating-a-sequence-for-a-varchar-in-PL/SQL

Upvotes: 1

acatt
acatt

Reputation: 487

You could use ROWNUM to get a unique number for a record:

UPDATE tableName
SET columnName = 'VC' || ROWNUM
WHERE columnName IS NULL
;

Upvotes: 4

Related Questions