Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL - Generate and update a column with different random number in every row

Need help with SQL - I want to generate and update a column in every row with a different random number.

Database # Oracle 10g.

Example - When I do something like this it updates all the rows with the same number

update mytable r 
set r.generated_num = 
(select floor(dbms_random.value(100,9999999)) from dual).

Any advice?

like image 636
jagamot Avatar asked Dec 28 '22 08:12

jagamot


1 Answers

Looks like sub-query is the problem.

This seems to be working-

update mytable r set r.generated_num = TRUNC(dbms_random.value(1,9999999))
like image 109
jagamot Avatar answered Dec 29 '22 21:12

jagamot