ORA-00913: oracle 子查询中的值太多
Posted
技术标签:
【中文标题】ORA-00913: oracle 子查询中的值太多【英文标题】:ORA-00913: too many values in oracle subquery 【发布时间】:2018-08-29 16:22:33 【问题描述】:我需要获取所有提供给候选人的工作机会,以及候选人最终被聘用的职位。我创建了两个单独的查询,一个捕获所有报价,一个子查询仅捕获每个候选人最终被聘用的工作。当我结合两个查询时出现问题,我得到 ORA-00913: too many values。有什么建议吗?
SELECT DISTINCT h.pi_candidate_num,
h.parent_pi_number,
h.associate_name,
j.job_family_name,
j.organization_name,
j.title,
e.contest_number,
e.pi_his_itm_app_trk_creation_dt offer_date
FROM wc_hired_interns_fa h
INNER JOIN wc_application_event_f e
ON h.pi_candidate_num = e.pi_candidate_num
INNER JOIN wc_job_information_d j
ON e.job_info_row_wid = j.row_wid
WHERE e.pi_his_itm_app_trk_creation_dt IN
(SELECT DISTINCT e.pi_his_itm_app_trk_creation_dt
FROM wc_application_event_f e
INNER JOIN wc_hired_interns_fa h
ON h.pi_candidate_num = e.pi_candidate_num
INNER JOIN wc_job_information_d j
ON e.job_info_row_wid = j.row_wid
WHERE j.job_family_name IN ('MDP', 'ELP', 'Emerging Leader Program', 'Other')
AND e.pi_his_itm_app_trk_sts_name = 'Extended'
AND e.pi_his_itm_app_trk_step_name = 'Offer'
AND j.title NOT IN ('Student Ambassador Program for Eligible Summer Interns', 'Student Ambassador'))
AND j.title IN (SELECT *
FROM (SELECT DISTINCT j.title full_time_detail,
rank() over(PARTITION BY e.pi_candidate_num ORDER BY e.pi_his_itm_app_trk_creation_dt DESC) AS rowrank
FROM wc_hired_interns_fa h
INNER JOIN wc_application_event_f e
ON h.pi_candidate_num = e.pi_candidate_num
INNER JOIN wc_job_information_d j
ON e.job_info_row_wid = j.row_wid
AND j.job_family_name IN ('MDP', 'ELP', 'Emerging Leader Program', 'Other')
AND e.pi_his_itm_app_trk_sts_name = 'Hired - External'
AND e.pi_his_itm_app_trk_step_name = 'Hire'
AND j.title NOT IN ('Student Ambassador Program for Eligible Summer Interns', 'Student Ambassador'))
WHERE rowrank = 1);
【问题讨论】:
【参考方案1】:当前的问题似乎是这部分:
...
AND J.TITLE IN (
SELECT * FROM (
SELECT DISTINCT J.TITLE FULL_TIME_DETAIL,
RANK () OVER (PARTITION BY E.PI_CANDIDATE_NUM ORDER BY E.PI_HIS_ITM_APP_TRK_CREATION_DT DESC) AS ROWRANK
FROM WC_HIRED_INTERNS_FA H
...
SELECT *
表示子查询返回两个列值,FULL_TIME_DETAIL
和 ROWRANK
。不过,您实际上并不想要 ROWRANK
,因此请将 *
更改为您想要的列:
...
AND J.TITLE IN (
SELECT FULL_TIME_DETAIL FROM (
SELECT DISTINCT J.TITLE FULL_TIME_DETAIL,
RANK () OVER (PARTITION BY E.PI_CANDIDATE_NUM ORDER BY E.PI_HIS_ITM_APP_TRK_CREATION_DT DESC) AS ROWRANK
FROM WC_HIRED_INTERNS_FA H
...
您正在执行大量子查询并重复大量代码,因此这可能会大大简化;也许研究分析函数。不过,这超出了这个问题和具体错误的范围。
【讨论】:
感谢您的建议,但是在进行了您推荐的更改后,即使错误清除了,我也没有得到预期的结果,这是某人被雇用的职位。 就像我说的,这超出了这个问题的范围。正如我认为我对上一个问题的评论,您确实需要提供an MCVE 并准确解释您想要看到的内容,以及为什么您当前的代码没有按照您的意愿执行。不过,这将是另一个新问题。不过,我会暗示,您的子查询可能需要连接(或消除),并且您可以使用案例表达式和分析函数来更接近我认为您的目标;所以你可能应该探索这条路,然后在遇到困难时提出一个新问题。以上是关于ORA-00913: oracle 子查询中的值太多的主要内容,如果未能解决你的问题,请参考以下文章