更新:伙计们,我正在将教员 ID 列表传递给存储过程,当我传递超过 10 个教员 ID 时,处理数据需要很长时间并且有时会超时。我花了很多时间调试这个查询,发现 proc 中的最后一行导致查询超时/响应时间慢。最后一行是 CTE 的子查询。如何重写/优化 proc 的最后一行以使我的查询运行得更快。任何帮助将不胜感激。有人可以帮忙吗?
create or replace PROCEDURE sp_Test(
facultycode IN varchar2
//few more variables
---
---
p_result OUT sys_refcursor
)
AS
open recordset for
//this parses list of id's i.e('101''102''104'108') and i am calling this in last line of my proc
with faculty_list as (
SELECT REGEXP_SUBSTR(facultycode,'[^,]+',1,LEVEL) AS FAC_CODE
FROM DUAL
CONNECT BY LEVEL <=LENGTH (REGEXP_REPLACE(facultycode,'[^,]+'))+1
)
select s.s_name, m.score, s.status
from student s
join marks m on s.s_id = m.s_id
WHERE S.GRADE>5
AND facultycode is null or s.fac_code in (select FAC_CODE from faculty_list); //this line
is making query very slow, I need to optimize this line for faster response
END sp_Test;