【问题标题】:Suggestion to make a massive insert建议制作大量插入
【发布时间】:2020-05-04 11:48:36
【问题描述】:

我有以下表格:

tb_profile   tb_mbx     tb_profile_mbx   tb_profile_cd
id           id         id_profile       id_perfil 
cod_mat      mbx        id_mbx           id_cd (matches id_mbx)
concil                  bp
                        masc
  • 我需要在验证 id_cd 1,2,4,5 时创建一个查询 和 6 存在于 tb_profile_cd 中,在 带有 tb_profile 的 cod_matrix 参数的 tb_profile_mbx 表 表。

  • 记住每个 concil 在 tb_mbx 表中都有自己的 ID 和一个 concil 有很多 cod_mat。

  • 还有一点是concil id_mbx代表了 tb_profile_cd 表。

  • 还有一点是,正如我上面所说,一个 concil 有很多 鳕鱼垫。每个 concil 大约有 2 万条记录。

根据我的需要,尝试查阅下面的查询,但Oracle返回错误:

insert into tb_profile_mbx values (seq_profile_mbx.nextval,
     (select id from tb_profile where concil like '%NEXXERA%')
    ,(select id from tb_mbx where mbx like '%NEXXERA%')
    ,null
    ,null);

ORA-01427: 单行子查询返回多于一行

是否有另一种方法来执行此查询?

提前致谢!

【问题讨论】:

  • insert into tb_profile_mbx select seq_profile_mbx.nextval, id, ... from tb_profile ...
  • 请提供样本数据和期望的结果。

标签: sql oracle sql-insert


【解决方案1】:

您可以使用以下方法插入所有匹配的匹配组合:

insert into tb_profile_mbx (id_profile, id_mbx) 
    select p.id, m.id
    from tb_profile p join
         tb_mbx m
         on p.concil like '%NEXXERA%' and m.mbx like '%NEXXERA%';

我建议运行select 以查看它是否返回您想要的值。

您只为tb_profile_mbx 显示两列,所以我只在insert 中包含两列。

【讨论】:

  • select 正确返回了 ID,但是为了执行插入,我需要再包含两个始终为 null 的字段,例如:id_perfil, id_mbx, bp(null), masc(null);
  • @devnan 。 . .列出INSERT 中的列,只需将NULL 添加到SELECT 中的相应位置即可。
猜你喜欢
  • 1970-01-01
  • 2010-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-16
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
相关资源
最近更新 更多