ORA-01427:单行子查询返回多行 - 如何修复?
Posted
技术标签:
【中文标题】ORA-01427:单行子查询返回多行 - 如何修复?【英文标题】:ORA-01427:single-row subquery returns more than one row - how to fix? 【发布时间】:2016-10-25 13:27:23 【问题描述】:我有一个查询,目的是输出所有具有"PPC"
角色的电子邮件以及这些 PPC 所属的"paygroups"
。
paygroup
可以有多个PPCs
。
每个PPC
可能有一个email address 1
和/或一个email address 2
。
当我使用测试paygroup(BOX)
时,查询工作正常,但是当我注释该行以查询所有paygroups
以返回所有paygroups
中的所有PPCs
时,我收到错误"single-row subquery returns more than one row"
.
SELECT
auth.paygroup,
per.NAME,
per.email_address AS "Personal email",
per.email_address2 AS "Business email"
FROM ps_personal_data per
INNER JOIN ps_ts_ee_auth auth
ON auth.emplid=per.emplid
INNER JOIN PS_SMS_SUBSCRB_TBL SUB
ON SUB.SUBSCRIBER_ID = AUTH.PAYGROUP
WHERE 1=1
AND SUB.EFFDT = (SELECT max (SUB2.effdt) FROM PS_SMS_SUBSCRB_TBL SUB2
WHERE SUB.SUBSCRIBER_ID = SUB2.SUBSCRIBER_ID AND SUB.EFF_STATUS = 'A')
AND auth.user_name = (SELECT R1.USER_NAME FROM PS_TS_CONTACT_ROLE R1
WHERE 1=1
AND R1.contact_role = 'PPC'
--AND R1.paygroup = 'BOX' --commenting this line out causes the error. It works fine when line is active
AND R1.action_dt = (SELECT MAX (R2.action_dt)
FROM PS_TS_CONTACT_ROLE R2
WHERE 1=1
AND R1.paygroup = R2.paygroup
AND R1.contact_role =
R2.contact_role))
【问题讨论】:
第 1 步 - 确定您想要的行。 【参考方案1】:SELECT
auth.paygroup,
per.NAME,
per.email_address AS "Personal email",
per.email_address2 AS "Business email"
FROM ps_personal_data per
INNER JOIN ps_ts_ee_auth auth
ON auth.emplid=per.emplid
INNER JOIN PS_SMS_SUBSCRB_TBL SUB
ON SUB.SUBSCRIBER_ID = AUTH.PAYGROUP
WHERE 1=1
AND SUB.EFFDT = (SELECT max (SUB2.effdt) FROM PS_SMS_SUBSCRB_TBL SUB2
WHERE SUB.SUBSCRIBER_ID = SUB2.SUBSCRIBER_ID AND SUB.EFF_STATUS = 'A')
AND auth.user_name in (SELECT R1.USER_NAME FROM PS_TS_CONTACT_ROLE R1 -- Change = to in
WHERE 1=1
AND R1.contact_role = 'PPC'
AND R1.paygroup = 'BOX' --commenting this line out causes the error. It works fine when line is active
AND R1.action_dt = (SELECT MAX (R2.action_dt)
FROM PS_TS_CONTACT_ROLE R2
WHERE 1=1
AND R1.paygroup = R2.paygroup
AND R1.contact_role =
R2.contact_role))
【讨论】:
好了,没有更多错误信息了。但是你确定它会返回 OP 所期望的吗?以上是关于ORA-01427:单行子查询返回多行 - 如何修复?的主要内容,如果未能解决你的问题,请参考以下文章
ORA-01427: 单行子查询在使用 GUID(sys_Guid()) 设置父子关系时返回多行