当我在sql developer中执行以下查询时,我收到以下错误消息 " Ora-01427单行子查询返回多行"
select TPNATIVENAME as PTPNAME,
INTERFACENAME as CTPNAME,
DIRECTIONALITY,
NENAME,
NCNAME
from TP ,
(select DIRECTIONALITY
from SNCCOMPONENT
where SNCID =
(select unique SNCID
from AFFECTEDXCS
where PXCID = -124)),
(select NODE.NAME as NENAME,
NC.NAME as NCNAME
from NODE NODE,
NETWORKCONTROLLER NC
where NODE.HANDLE =
(select unique SRCNEID
from SNCCOMPONENT
where SNCID =
(select unique SNCID
from AFFECTEDXCS
where PXCID = -124))
and NC.HANDLE = NODE.NCHANDLE)
where NEID =
(select SRCNEID
from SNCCOMPONENT
where SNCID =
(select unique SNCID
from AFFECTEDXCS
where PXCID = -124))
and TPID =
(select SRCTP
from SNCCOMPONENT
where SNCID =
(select unique SNCID
from AFFECTEDXCS
where PXCID = -124))
union
select TPNATIVENAME as PTPNAME,
INTERFACENAME as CTPNAME,
DIRECTIONALITY,
NENAME,
NCNAME
from TP,
(select DIRECTIONALITY
from SNCCOMPONENT
where SNCID =
(select unique SNCID
from AFFECTEDXCS
where PXCID = -124)),
(select NODE.NAME as NENAME,
NC.NAME as NCNAME
from NODE NODE,
NETWORKCONTROLLER NC
where NODE.HANDLE =
(select unique SRCNEID
from SNCCOMPONENT
where SNCID =
(select unique SNCID
from AFFECTEDXCS
where PXCID = -124))
and NC.HANDLE = NODE.NCHANDLE)
where NEID =
(select SINKNEID
from SNCCOMPONENT
where SNCID =
(select unique SNCID
from AFFECTEDXCS
where PXCID = -124))
and TPID =
(select SINKTP
from SNCCOMPONENT
where SNCID =
(select unique SNCID
from AFFECTEDXCS
where PXCID = -124));
我没有得到哪个内部查询返回多个值以及如何解决此错误?
答案 0 :(得分:1)
SELECT UNIQUE X FROM Y
此查询不保证您的查询将返回单行。它可能会返回多行。它只能保证它不会多次返回相同的X.
因此,您需要使用IN
代替=
。
例如:
SELECT SINKTP FROM SNCCOMPONENT
WHERE SNCID IN (SELECT UNIQUE SNCID FROM AFFECTEDXCS WHERE PXCID = -124)
答案 1 :(得分:0)
确保这些SQL只为您提供一个值:
SELECT UNIQUE SNCID
FROM AFFECTEDXCS
WHERE PXCID = -124
SELECT SRCNEID
FROM SNCCOMPONENT
WHERE SNCID = (
SELECT UNIQUE SNCID
FROM AFFECTEDXCS
WHERE PXCID = -124
)
SELECT UNIQUE SRCNEID
FROM SNCCOMPONENT
WHERE SNCID = (
SELECT UNIQUE SNCID
FROM AFFECTEDXCS
WHERE PXCID = -124
)
SELECT SINKNEID
FROM SNCCOMPONENT
WHERE SNCID = (
SELECT UNIQUE SNCID
FROM AFFECTEDXCS
WHERE PXCID = -124
)
SELECT SINKTP
FROM SNCCOMPONENT
WHERE SNCID = (
SELECT UNIQUE SNCID
FROM AFFECTEDXCS
WHERE PXCID = -124
)
如果一个(或多个)返回多行,作为快速解决方案,您可以将rownum < 2
谓词添加到where子句或将=
符号替换为{ {1}}字。