oracle 在表的每一行中插入一个随机数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4595982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
insert a random number into each row in table
提问by Captastic
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.
我目前有一个包含大约 600,000 行的 oracle 表 (lovalarm)。我需要能够运行一个查询,该查询将遍历每一行并将字段 (lovsiteid) 更新为 14300 到 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
非常感谢,卡普
回答by Michael Pakhantsov
Just not use subquery:
只是不使用子查询:
update lovalarm
set lovsiteid = TRUNC(dbms_random.value(14300,17300))
回答by bavaga
Try this:
尝试这个:
update lovalarm set lovsiteid = (select FLOOR(RAND() * (17300 - 14300) + 14300))
works in MySQL
在 MySQL 中工作