我们有一个在oracle中使用下面的sql的场景,它使用一个Case语句沿着一个子查询,我在尝试执行它时得到以下错误消息。
我得到的错误:
ORA-01427:单行子查询返回多行01427。00000 -“单行子查询返回多行”
SELECT DISTINCT
P.AGNT_NO,
P.AGENCY_NO,
AP.AGRMNT_ID,
P.SRC_CD,
PR.PARTY_ROLE_NM,
APR.AGNT_PARTCPTN_FCTR_NO
FROM
EODS.PARTY_EV P
INNER JOIN EODS.AGRMNT_PARTY_EV AP ON P.PARTY_ID = AP.PARTY_ID
INNER JOIN EODS.AGRMNT_PARTY_ROLE_EV APR ON AP.AGRMNT_PARTY_ID = APR.AGRMNT_PARTY_ID
INNER JOIN EODS_REF.REF_PARTY_ROLE_RV PR ON APR.PARTY_ROLE_ID = PR.SRC_ROLE_ID
AND PR.PARTY_ROLE_NM IN ('SERVICING AGENT','WRITING AGENT')
INNER JOIN EODS.CVRG C ON AP.AGRMNT_ID = C.AGRMNT_ID
INNER JOIN EODS_REF.REF_PROD_RV RP ON C.PROD_ID = RP.SRC_PROD_ID
WHERE
PR.PARTY_ROLE_NM =
CASE
WHEN P.SRC_CD = 'PRD4' THEN 'SERVICING AGENT'
WHEN (P.SRC_CD = 'ELS' AND RP.PLAN_CD = 'FMYMVAY0') THEN 'SERVICING AGENT'
WHEN (P.SRC_CD = 'ELS' AND RP.PLAN_CD = 'INSELDZ0') THEN 'SERVICING AGENT'
WHEN (P.SRC_CD = 'ELS' AND RP.PLAN_CD = 'SENSELZ0') THEN 'SERVICING AGENT'
WHEN (P.SRC_CD IN ('CLIC','PRD5')) THEN (SELECT
PARTY_ROLE_NM
FROM
(
SELECT
RNK,
PARTY_ROLE_NM
FROM
(
SELECT
P.AGNT_NO,
P.AGENCY_NO,
AP.AGRMNT_ID,
P.SRC_CD,
RANK() OVER(PARTITION BY
AP.AGRMNT_ID
ORDER BY
PR.PARTY_ROLE_NM
DESC
) RNK,
PR.PARTY_ROLE_NM,
APR.AGNT_PARTCPTN_FCTR_NO
FROM
EODS.PARTY_EV P
INNER JOIN EODS.AGRMNT_PARTY_EV AP ON P.PARTY_ID = AP.PARTY_ID
INNER JOIN EODS.AGRMNT_PARTY_ROLE_EV APR ON AP.AGRMNT_PARTY_ID = APR.AGRMNT_PARTY_ID
INNER JOIN EODS_REF.REF_PARTY_ROLE_RV PR ON APR.PARTY_ROLE_ID = PR.SRC_ROLE_ID
WHERE
PR.PARTY_ROLE_NM IN ('SERVICING AGENT','WRITING AGENT')
)
WHERE
RNK = 1
)
)
ELSE 'WRITING AGENT'
END
2条答案
按热度按时间izj3ouym1#
RANK
解析函数可以返回每个分区中排名第一的多个行,如果有多个行被ORDER BY
子句相同地排序。如果这是原因,那么您可以考虑将
RANK
更改为ROW_NUMBER
,这将在每个分区中仅具有单个行号。1.如果在
RANK
ing中有多个分区,那么在每个分区中都会有排在第一位的行,并且CASE
表达式期望从子查询中返回一行。要修复它,您可以聚合:
1.您可能忘记将外部查询与子查询关联起来:
m3eecexj2#
在子查询中
put count(*)查看是否有重复项