Sql 如何修复ORA-01427单行子查询返回多行
每当我添加LastTerm下面列出的代码的缩进部分时,错误ORA-01427单行子查询返回的行数超过一行是由SQL工具返回的。如果我从列表中的代码部分删除了它,它将运行并正确地从表中提取我请求的数据。我需要更改或修复什么才能使它与代码中的最后一个术语部分一起运行,而不是接收到错误?我不确定我做错了什么,我也不确定另外两个,少校和站着的,为什么要跑 在此方面的任何帮助都将不胜感激Sql 如何修复ORA-01427单行子查询返回多行,sql,oracle,Sql,Oracle,每当我添加LastTerm下面列出的代码的缩进部分时,错误ORA-01427单行子查询返回的行数超过一行是由SQL工具返回的。如果我从列表中的代码部分删除了它,它将运行并正确地从表中提取我请求的数据。我需要更改或修复什么才能使它与代码中的最后一个术语部分一起运行,而不是接收到错误?我不确定我做错了什么,我也不确定另外两个,少校和站着的,为什么要跑 在此方面的任何帮助都将不胜感激 SELECT DISTINCT (c.sfrstcr_pidm)PIDM, substr(frkiden.f_get_
SELECT DISTINCT (c.sfrstcr_pidm)PIDM,
substr(frkiden.f_get_spriden_id(c.sfrstcr_pidm),1,9) ID,
substr(frkiden.f_get_spriden_first_name(c.sfrstcr_pidm),1,15) FIRST,
substr(frkiden.f_get_spriden_last_name(c.sfrstcr_pidm),1,60) LAST,
sovclas_clas_code,shrlgpa_gpa,spbpers_ethn_code,spbpers_sex,
(select x. sgbstdn_majr_code_1
from sgbstdn x where x.sgbstdn_pidm = c.sfrstcr_pidm
and x.sgbstdn_term_code_eff =
(select max(y. sgbstdn_term_code_eff) from sgbstdn y
where x. sgbstdn_pidm = y. sgbstdn_pidm
and y. sgbstdn_majr_code_1 is not null)) Major,
(select x.shrttrm_astd_code_end_of_term
from shrttrm x where x.shrttrm_pidm = c.sfrstcr_pidm
and x.shrttrm_term_code =
(select max(y.shrttrm_term_code) from shrttrm y
where x.shrttrm_pidm = y.shrttrm_pidm
and y.shrttrm_astd_code_end_of_term is not null)) Standing,
(select x.sfrstcr_term_code
from sfrstcr x where x.sfrstcr_pidm = c.sfrstcr_pidm
and x.sfrstcr_term_code =
(select max(y.sfrstcr_term_code) from sfrstcr y
where x.sfrstcr_pidm = y.sfrstcr_pidm
and y.sfrstcr_term_code IS NOT NULL )) LastTerm
FROM
sovclas,spbpers,shrlgpa,sfrstcr c
LEFT JOIN goremal
ON c.sfrstcr_pidm = goremal_pidm
AND goremal_emal_code = 'UNIV'
AND goremal_status_ind != 'I'
WHERE
c.sfrstcr_pidm = shrlgpa_pidm
AND c.sfrstcr_term_code = sovclas_term_code
AND c.sfrstcr_pidm = sovclas_pidm
AND c.sfrstcr_pidm = spbpers_pidm
AND shrlgpa_levl_code = 'UG'
AND shrlgpa_gpa_type_ind = 'O'
AND c.sfrstcr_term_code = sovclas_term_code
AND c.sfrstcr_term_code = '201510'
AND c.sfrstcr_rsts_code IN ('RE','RW','RL')
AND sovclas_clas_code NOT IN ('GR','ES')
AND c.sfrstcr_pidm IN
(SELECT DISTINCT(a.shrttrm_pidm)
FROM shrttrm a
WHERE a.shrttrm_astd_code_end_of_term IN ('S1','S2','S3','S4')
AND a.shrttrm_term_code =
(SELECT Max(b.shrttrm_term_code)
FROM shrttrm b
WHERE b.shrttrm_pidm = a.shrttrm_pidm AND
b.shrttrm_term_code < 201510 )) -- Change the code to the latest term without standing
AND c.sfrstcr_pidm IN
(SELECT DISTINCT(a.sgbstdn_pidm)
FROM sgbstdn a
WHERE a.sgbstdn_levl_code != 'GR'
AND a.sgbstdn_styp_code NOT IN ('L')
AND a.sgbstdn_term_code_eff =
(SELECT Max(b.sgbstdn_term_code_eff)
FROM sgbstdn b
WHERE b.sgbstdn_pidm = a.sgbstdn_pidm))
AND c.sfrstcr_pidm IN
(SELECT DISTINCT(a.sfrstcr_pidm)
FROM sfrstcr a
WHERE a.sfrstcr_rsts_code IS NOT NULL
AND a.sfrstcr_term_code =
(SELECT Max(b.sfrstcr_term_code)
FROM sfrstcr b
WHERE b.sfrstcr_pidm = a.sfrstcr_pidm AND
b.sfrstcr_term_code < '201510'))
尝试按如下方式添加rownum=1:
(select x.shrttrm_astd_code_end_of_term
from shrttrm x where x.shrttrm_pidm = c.sfrstcr_pidm
and x.shrttrm_term_code =
(select max(y.shrttrm_term_code) from shrttrm y
where x.shrttrm_pidm = y.shrttrm_pidm
and y.shrttrm_astd_code_end_of_term is not null
and rownum = 1)) Standing
对于驱动查询的至少一些行,即一些c.sfrstcr_pidm值,子查询返回多行。您需要更改子查询,以便为每个c.sfrstcr\u pidm值返回一行。由于您没有告诉我们有关您的数据模型、数据或需求的任何信息,因此我们只能告诉您更多信息。感谢您的提示,但在进行更改时,我仍然收到相同的错误。从sfrstcr x中选择x.sfrstcr_term_code,其中x.sfrstcr_pidm=c.sfrstcr_pidm和x.sfrstcr_term_code=从sfrstcr y中选择maxy.sfrstcr_term_code,其中x.sfrstcr_pidm=y.sfrstcr_pidm和y.sfrstcr_term_code不为NULL,rownum=1 lasterm这是数据问题。在某些情况下,另外两个部分也可能返回多行
(select max(x.sfrstcr_term_code)
from sfrstcr x where x.sfrstcr_pidm = c.sfrstcr_pidm
and x.sfrstcr_term_code =
(select max(y.sfrstcr_term_code) from sfrstcr y
where x.sfrstcr_pidm = y.sfrstcr_pidm
and y.sfrstcr_term_code IS NOT NULL )) LastTerm