SQL复杂查询的ORA-22813错误

时间:2009-01-15 18:59:04

标签: sql

我有一个很大的SELECT语句,里面有很多嵌套选择。当我运行它时,它会给我一个ORA-22813错误:

  

Ora-22813: - 来自其中一个内部子查询的Collection值超出了系统限制,因此出现了此错误。

我在下面给出了一些返回大量数据的嵌套select

---第一个select返回的数据最多。

我是否可以以任何替代方式处理和处理INNER SELECT返回到表中的大量数据,这样就不会出现内存错误,排序大小更少。 get,任何其他方式,以便QUERY成功处理而不会出错。

/*****************************************BEGIN

LEFT OUTER JOIN
     (  SELECT *

        FROM STUDENT_COURSE stu_c 

        LEFT OUTER JOIN STUDENT_history ch on stu_c.course_id = ch.ch_course_id 

        LEFT OUTER JOIN STUDENT_master stu_mca on ch.course_history_id = stu_mca.item_id

      ) stu_c ON stu_c.HISTORY_ID = toa.ACTIVITY_ID               ----->This table is joined earlier

LEFT OUTER JOIN

    (SELECT c_e.EV_ID, c_e.EV_NAME, ma.item_id, ma.cata_id
FROM EVENTS c_e LEFT OUTER  
JOIN COURSE_master ma on c_e.event_Id = ma.item_id ) c_e ON c_e.EVENT_ID = toa.ACTIVITY_ID

在这些选择之后---我们有GROUP_BY来进一步排序。

---我已经检查过,如果我加上额外的限制资格 与where rownum <30,<20中的每个SELECT中的SELECT * FROM (SELECT mcat.CATALOG_ITEM_ID, mcat.CATALOG_ITEM_NAME , mcat.DESCRIPTION, mcat.CATALOG_ITEM_TYPE, mcat.DELIVERY_METHOD, XMLElement("TRAINING_PLAN",XMLAttributes( TP.TPLAN_ID as "id" ), XMLELEMENT("COMPLETE_QUANTITY", TP.COMPLETE_QUANTITY), XMLELEMENT("COMPLETE_UNIT", TP.COMPLETE_UNIT), XMLElement("TOTAL_CREDITS", TP.numberOfCredits ), XMLELEMENT("IS_CREDIT_BASED", TP.IS_CREDIT_BASED), XMLELEMENT("IS_FOR_CERT", TP.IS_FOR_CERT), XMLELEMENT("ACCREDIT_ORG_NAME", TP.ACCRED_ORG_NAME), XMLELEMENT("ACCREDIT_ORG_ID", TP.accredit_org_id ), XMLElement("OBJECTIVE_LIST", TP.OBJECTIVE_LIST ) ).extract('/').getClobVal() AS PLAN_LIST FROM student_master_catalog mcat INNER JOIN (SELECT stu_tp.TPLAN_ID, stu_tp.COMPLETE_QUANTITY, stu_tp.COMPLETE_UNIT, stu_tp.TPLAN_XML_DATA.extract('//numberOfCredits/text()').getStringVal() as numberOfCredits, stu_tp.IS_CREDIT_BASED, stu_tp.IS_FOR_CERT, stu_oa.ACCRED_ORG_NAME, stu_tp.TPLAN_XML_DATA.extract('//accreditingOrg/text()').getStringVal() as accredit_org_id, objective_list.OBJECTIVE_LIST FROM student_training_catalog stu_tp LEFT OUTER JOIN stu_accrediting_org stu_oa on stu_tp.TPLAN_XML_DATA.extract('//accreditingOrg/text()').getStringVal() = stu_oa.ACCRED_ORG_ID INNER JOIN (SELECT * FROM (SELECT stu_tpo.TPLAN_ID AS OBJECTIVE_TPLAN_ID, XMLAgg( XMLElement("OBJECTIVE", XMLElement("OBJECTIVE_ID",stu_tpo.T_OBJECTIVE_ID ), XMLElement("OBJECTIVE_NAME",stu_to.T_OBJECTIVE_NAME ), XMLElement("OBJECTIVE_REQUIRED_CREDITS_OR_ACTIVITIES",stu_tpo.REQUIRED_CREDITS ), XMLElement("ITEM_ORDER", stu_tpo.ITEM_ORDER ), XMLElement("ACTIVITY_LIST", activity_list.ACTIVITY_LIST ) ) ) as OBJECTIVE_LIST FROM stu_TP_OBJECTIVE stu_tpo INNER JOIN stu_TRAINING_OBJECTIVE stu_to ON stu_tpo.T_OBJECTIVE_ID = stu_to.T_OBJECTIVE_ID INNER JOIN (SELECT * FROM (SELECT stu_toa.T_OBJECTIVE_ID AS ACTIVITY_TOBJ_ID, XMLAgg( XMLElement("ACTIVITY", XMLElement("ACTIVITY_ID",stu_toa.ACTIVITY_ID ), XMLElement("CATALOG_ID",COALESCE(stu_c.CATALOG_ID, COALESCE( stu_e.CATALOG_ID, stu_t.CATALOG_ID ) ) ), XMLElement("CATALOG_ITEM_ID",COALESCE(stu_c.CATALOG_ITEM_ID, COALESCE( stu_e.CATALOG_ITEM_ID, stu_t.CATALOG_ITEM_ID ) ) ), XMLElement("DELIVERY_METHOD",COALESCE(stu_c.DELIVERY_METHOD, COALESCE( stu_e.DELIVERY_METHOD, stu_t.DELIVERY_METHOD ) ) ), XMLElement("ACTIVITY_NAME",COALESCE(stu_c.COURSE_NAME, COALESCE( stu_e.EVENT_NAME, stu_t.TEST_NAME ) ) ), XMLElement("ACTIVITY_TYPE",initcap( stu_toa.ACTIVITY_TYPE ) ), XMLElement("IS_REQUIRED",stu_toa.IS_REQUIRED ), XMLElement("IS_PREFERRED",stu_toa.IS_PREFERRED ), XMLElement("NUMBER_OF_CREDITS",stu_lac.CREDIT_HOURS), XMLElement("ITEM_ORDER", stu_toa.ITEM_ORDER ) )) as ACTIVITY_LIST FROM stu_TRAIN_OBJ_ACTIVITY stu_toa LEFT OUTER JOIN ( SELECT distinct lac.LEARNING_ACTIVITY_ID, lac.CREDIT_HOURS FROM student_training_catalog tp INNER JOIN stu_TP_OBJECTIVE tpo on tp.TPLAN_ID = tpo.TPLAN_ID INNER JOIN stu_TRAIN_OBJ_ACTIVITY toa on tpo.T_OBJECTIVE_ID = toa.T_OBJECTIVE_ID INNER JOIN stu_LEARNINGACTIVITY_CREDITS lac on lac.LEARNING_ACTIVITY_ID = toa.ACTIVITY_ID and tp.TPLAN_XML_DATA.extract ('//accreditingOrg/text()').getStringVal() = lac.ACC_ORG_ID where tp.tplan_id ='*************' ) stu_lac ON stu_lac.LEARNING_ACTIVITY_ID = stu_toa.ACTIVITY_ID ------>This Select returns correct no. of rows 一样,它可以正常工作。


完整查询

SELECT

我想加入以下嵌套stu_toa.ACTIVITY_IDSELECT。这将解决我的问题。

LEFT OUTER JOIN内的LEFT OUTER JOIN ( SELECT ch.COURSE_HISTORY_ID, stu_c.COURSE_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method FROM stu_COURSE stu_c LEFT OUTER JOIN stu_course_history ch on stu_c.course_id = ch.ch_course_id - --If I can qualify here with ch.ch_course_id = stu_toa.ACTIVITY_ID (stu_toa.ACTIVITY_ID from the above select with correct no. of rows ) --Here, I get errors because I can't access outside values inside a left outer join LEFT OUTER JOIN student_master_catalog mca on ch.course_history_id = mca.catalog_item_id ) stu_c ON stu_c.COURSE_HISTORY_ID = stu_toa.ACTIVITY_ID LEFT OUTER JOIN (SELECT stu_e.EVENT_ID, stu_e.EVENT_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method FROM stu_EVENTS stu_e LEFT OUTER JOIN student_master_catalog mca on stu_e.event_Id = mca.catalog_item_id ) stu_e ON stu_e.EVENT_ID = stu_toa.ACTIVITY_ID LEFT OUTER JOIN (SELECT stu_t.TEST_HISTORY_ID, stu_t.TEST_NAME, mca.catalog_item_id, mca.catalog_id, mca.delivery_method FROM stu_TEST_HISTORY stu_t LEFT OUTER JOIN student_master_catalog mca on stu_t.test_history_id = mca.catalog_item_id) stu_t ON stu_t.test_history_id = stu_toa.ACTIVITY_ID GROUP BY stu_toa.T_OBJECTIVE_ID) ) activity_list ON activity_list.ACTIVITY_TOBJ_ID = stu_tpo.T_OBJECTIVE_ID GROUP BY stu_tpo.TPLAN_ID) ) objective_list ON objective_list.OBJECTIVE_TPLAN_ID = stu_tp.TPLAN_ID )TP ON TP.TPLAN_ID = mcat.CATALOG_ITEM_ID WHERE mcat.CATALOG_ITEM_ID = '*****************' and mcat.CATALOG_ORG_ID = '********') 下方是问题所在。它返回太多,因为3个表直接连接而没有任何值限制。

{{1}}

3 个答案:

答案 0 :(得分:2)

请发布DDL,大致尺寸(相对于彼此)和完整查询,而不仅仅是摘录。

一些快速点击可能会或可能不会解决您的问题(为了更好的帮助,我需要更好的信息) -

  • 你确定你的意思是OUTER加入吗?外部加入学生课程意味着没有参加任何课程的学生仍然会参加。这是期望的行为吗?

  • 如果您只想要有限的列子集,请不要select *。枚举您需要的确切列。其余的可能看起来不是很多,但是当你乘以你拥有的总行数时,这种情况可能意味着内存中的排序和溢出到磁盘之间的差异。

答案 1 :(得分:0)

您正在查看多少行数据?有时,使用程序化聚合的单独查询可以更好地工作。对Oracle查询优化有更多了解的人也许可以提供帮助,同样,调整设置也可以帮助...

我有一个实例,其中调用了一个sproc,来自多个源的聚合数据比应用程序中的两个调用指数长得多,并将它们放在内存中。

答案 2 :(得分:0)

发布表格的DDL和查询的确切计划。

同时,尝试增加pga_aggregate_targetsort_area_sizehash_area_size