Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert a random number into each row in table

I currently have an oracle table (lovalarm) containing around 600,000 rows. I need to be able to run a query which will cycle through each row and update a field (lovsiteid) to a random number between 14300 and 17300.

So far I have:

update lovalarm
set lovsiteid = (select TRUNC(dbms_random.value(14300,17300)) FROM dual)

Sadly this picks a random number and then updates all rows with the same number which isn't exactly what I'm after!

Can anyone point me in the right direction?

Many thanks, Cap

like image 875
Captastic Avatar asked Dec 15 '25 10:12

Captastic


1 Answers

Just not use subquery:

update lovalarm
set lovsiteid = TRUNC(dbms_random.value(14300,17300))
like image 143
Michael Pakhantsov Avatar answered Dec 17 '25 01:12

Michael Pakhantsov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!