【问题标题】:Insert random strings,numbers. And result of multiplication插入随机字符串、数字。和乘法的结果
【发布时间】:2017-03-02 12:02:12
【问题描述】:

这是真的吗?

我想在此表中插入列 'valname' 字符串,这些字符串将以随机顺序为 (USD,EUR,RUB) 10000 次。

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

在 3d 列中 'should' 表示乘法量的结果 (如果美元 * 69)(如果欧元 * 72) (如果卢布 * 1.2)

例如

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

按级别连接

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

【问题讨论】:

标签: sql oracle oracle11g


【解决方案1】:
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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-08
    • 2016-02-07
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    相关资源
    最近更新 更多