Sql Insert into select from子句导致“无法插入多行错误”
我使用insert into select from子句向表中插入数据,但它不起作用 请看这里:Sql Insert into select from子句导致“无法插入多行错误”,sql,oracle,select,insert,Sql,Oracle,Select,Insert,我使用insert into select from子句向表中插入数据,但它不起作用 请看这里: insert into STAGES_ROLES_REL select (select stage_id from (select ws2.workflow_stage_id as stage_id from
insert into STAGES_ROLES_REL
select
(select stage_id
from
(select ws2.workflow_stage_id as stage_id
from
( select ws.workflow_stage_name as workflow_stage_name
from workflow_stages ws
join stages_roles_rel sr
on ws.workflow_stage_id = sr.workflow_stage_id ) table1
join workflow_stages ws2
on table1.workflow_stage_name = ws2.workflow_stage_name
order by ws2.workflow_stage_id))
,role_id
,current_date created_date, user created_by
,null modified_date, null modified_by
from stages_roles_rel
错误是无法插入多行,但我不知道如何放置筛选器和获取单个行
非常感谢你的帮助 我猜这个查询将返回多个结果:
select stage_id
from (
select ws2.workflow_stage_id as stage_id
from (
select ws.workflow_stage_name as workflow_stage_name
from workflow_stages AS ws
inner join stages_roles_rel AS sr
on ws.workflow_stage_id = sr.workflow_stage_id
) AS table1
inner join workflow_stages ws2
on table1.workflow_stage_name = ws2.workflow_stage_name
order by ws2.workflow_stage_id
)
如果您希望从该查询中删除多行,请将常量移动到该查询中,并删除外部查询:
insert into STAGES_ROLES_REL
select
stage_id,
role_id,
current_date AS created_date,
user AS created_by,
null AS modified_date,
null AS modified_by
from (
select ws2.workflow_stage_id as stage_id
from (
select ws.workflow_stage_name as workflow_stage_name
from workflow_stages AS ws
inner join stages_roles_rel AS sr
on ws.workflow_stage_id = sr.workflow_stage_id
) AS table1
inner join workflow_stages ws2
on table1.workflow_stage_name = ws2.workflow_stage_name
order by ws2.workflow_stage_id
)
[add a cross join to the original table if that's what you're wanting, I don't know the intent of your original query]
否则,您需要修复查询,使其仅返回一行。您的错误很可能是子查询返回的行数不能超过erow,因为您有标量子查询,无法控制返回的行数。是的,我知道它返回多行,但如何逐个提取行?