甲骨文,插入multirows从子查询与多行(Oracle, insert multirows fr

2019-09-23 13:20发布

我试着去一些领域从表到其他副本,我想通过插入像这样子查询做IY:

insert into sed_reporte_generico 
(srg_usuario, 
srg_nombres,
srg_ape_paterno,
srg_ape_materno,
srg_objetivo,
srg_peso_ob,
srg_calf_ob)
values
(
(select us.su_st_usuario, us.su_st_nombres, us.su_st_ap_paterno, us.su_st_ap_materno,     ob.soc_st_descripcion, ob.soc_nr_peso,ob.soc_nr_calificacion 
from sed_objetivo ob, sed_usuarios us, sed_evaluacion ev 
where ob.se_evaluacion_pk = ev.se_evaluacion_pk and ev.su_colaborador_fk =     us.su_usuarios_pk)
);

但我得到这个错误:

01427. 00000 -  "single-row subquery returns more than one row"

任何想法,我应该怎么办呢?

谢谢,

Answer 1:

觉得你有之间进行选择

insert into table (a, b, c) VALUES(1, 2, 3)

insert into table (a, b, c) 
(SELECT x, y, z from table2)

你可以有值,并且仅当您选择查询只返回一个列和一个行选择混合(由anomyous马尖的)!

顺便说一句,使用JOIN ...来加入你的表(使用WHERE子句的连接表是相当不好的习惯):

INSERT INTO sed_reporte_generico 
(srg_usuario, 
srg_nombres,
srg_ape_paterno,
srg_ape_materno,
srg_objetivo,
srg_peso_ob,
srg_calf_ob)

(select us.su_st_usuario, us.su_st_nombres, us.su_st_ap_paterno, us.su_st_ap_materno,     ob.soc_st_descripcion, ob.soc_nr_peso,ob.soc_nr_calificacion 
FROM sed_objetivo ob 
JOIN sed_evaluacion ev  ON ob.se_evaluacion_pk = ev.se_evaluacion_pk
JOIN sed_usuarios us on  ev.su_colaborador_fk =     us.su_usuarios_pk)
);


文章来源: Oracle, insert multirows from subquery with more than one row