【问题标题】:oracle - How to insert unique values from a table to another multiple times?oracle - 如何将一个表中的唯一值多次插入到另一个表中?
【发布时间】:2014-06-05 20:46:12
【问题描述】:

使用 Oracle 12c,例如,我在一个表 TABLEA 的 PK 列中有 5 行,其值为 1、2、3、4、5。我想将值插入另一个表TABLEB 3 次。所以 TABLE 在插入后会有 15 行,其值为 1,1,1,2,2,2,3,3,3,4,4,4,5,5,5。我怎样才能做到这一点?

我正在尝试创建一个脚本,该脚本将插入从 TABLEATABLEB 的值(如果它们尚不存在)。目前我手动将TABLEA 中的每个值插入TABLEB 3 次。

【问题讨论】:

    标签: sql oracle insert


    【解决方案1】:

    您可以使用cross join。查询看起来像这样:

    insert into t(pk)
        select pk
        from table t2 cross join
             (select 1 as n from dual union all select 2 from dual union all select 3 from dual
             ) n;
    

    【讨论】:

      猜你喜欢
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      相关资源
      最近更新 更多