首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

按照几率插入记录,该怎么解决

2012-03-16 
按照几率插入记录表中有两个字段A,B。A是几率值,B默认值是0,含义0是显示 1隐藏如果A为50,说明有50%的几率插

按照几率插入记录
表中有两个字段A,B。A是几率值,B默认值是0,含义0是显示 1隐藏
如果A为50,说明有50%的几率插入B的值为1
如果A为80,说明有80%的几率插入B的值为1.
这个该怎么写。。。用plsql的话

[解决办法]

SQL code
declare   -- Local variables here  random_num number;begin  -- Test statements here  for rec in (select id,A,B from test)  loop        select trunc(dbms_random.value(1,10))        into random_num        from dual;                if random_num <= rec.A           then                update test t set t.B = 1 where t.id = rec.id;         end if;    end loop;  end; 

热点排行
Bad Request.