插入随机字符串,数字。和乘法的结果

时间:2017-03-02 12:02:12

标签: sql oracle oracle11g

这是真的吗?

我希望在此表中插入列'valname'字符串,其随机顺序为(USD,EUR,RUB)10000次。

在第二栏'ammount'中     插入100-2000的随机数。 (10000次)

在3d专栏中     'should'表示乘法ammount的结果 (如果是美元* 69)(如果是欧元     * 72)(如果RUB * 1.2)

例如

valname = USD, ammount = 100, converted_ammount = 6900;
valname = EUR, ammount = 100, converted_ammount = 7200;
valname = RUB, ammount = 100,converted_ammount = 120;

按级别连接< = 10000;

    CREATE table t_test01 (    valname varchar2(5),    
ammount number null,    converted_ammount number null --- by multiplication
    * 69,72,1.2    )

1 个答案:

答案 0 :(得分:5)

insert into t_test01
 with x as (select case trunc(dbms_random.value*3) 
                     when 0 then 'EUR' 
                     when 1 then 'USD' 
                     else 'RUB' end currency,
             round(dbms_random.value(100,2000)) ammount
             from dual connect by rownum<=10000)
  select currency, ammount, 
         ammount* case currency 
            when 'USD' then 69 
            when 'EUR' then 72 
            else 1.2 end converted_ammount
    from x;