sql oracle 如何在给定数中取随机数?

如题,比如写一个UPDATE 语句,给表中某一个字段设置值,这些值只能在 1 ,5, 9之间取
有没有方法做到?谢谢

dbms_random.value(1,5) 要是取整外面再包个trunc()函数就可以了

update. tablename set sname ='xxx ' where id in (1,2,3);
更新tablename 这个表中的sname 字段里的只,条件在当id 取值为1,2,3中的任意一个

我的方法有点笨,但应该可以的,试试

update 表名 a
set a.更新字段 = (
select case when i.randoms = 2 then  5 
                      when i.randoms = 3 then 9
                      else i.randoms end as randoms from (select t.参照字段, trunc(dbms_random.value(1,4)) randoms
from 表名 t ) i where a.参照字段 = i.参照字段);

update tablename set 字段=(select case
when a.res < 4 then
1
when a.res < 7 then
5
else
9
end
from (select trunc(dbms_random.value(1, 9)) res from dual) a;
) where .........

你可以新建一个触发器,当你更新的时候,你会从这几个数里面随机取出来