0

I have to update a 'varchar2' column in a table with random values, but the catch is that the column is defined with 'unique' constraint, due to which I am getting the error saying that "Unique constraint violated".

Can somebody help please.

Thanks

Shaan44
  • 5
  • 1
  • 2

2 Answers2

1

You haven't given any constraints over what the values might be, so why not just set it to a set of known unique values, e.g. integers:

UPDATE table_name SET unique_col = TO_CHAR(ROWNUM);
Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
0

you can use the DBMS_RANDOM package to create the random values and insert the same in table like below

INSERT INTO table_name(unique_col) values (DBMS_RANDOM.string('a',n);

here n can be max value of table. For more information refer here http://oracle-base.com/articles/misc/dbms_random.php

The value generated will be unique depends on the length of the value

Exhausted
  • 1,867
  • 2
  • 23
  • 33