请尽可能帮助我,如果要更快地迭代这些值,我需要优化下面的代码块。见下面的陈述:
for CONSULTANT_RECORD IN CONSULTANT_CURSOR LOOP /*Loop 2*/
VData := VData||crlf2||CONSULTANT_RECORD.USER_FIRSTNAME||' '||CONSULTANT_RECORD.USER_SURNAME;
vTOT_LOG_CLOSED4USER := 0;
vAVERAGE_DAY := 0;
vTOT_DAYS := 0;
for x in 1..vlastday loop /*Loop 3*/
select COUNT(DISTINCT LOG_NO) as "LOG_COUNT" INTO vLOG_COUNTER
FROM DMS_CRM.TBL_DMS_SERVICE_REQUESTS_HIST
WHERE LOG_STATUS = 'Resolved'
AND TO_CHAR(HIST_DATE_TIME_STAMP, 'MONTH,YYYY') = TO_CHAR(SYSDATE, 'MONTH,YYYY')
AND TO_CHAR(HIST_DATE_TIME_STAMP, 'DD') = lpad(to_char(x),2,'0')
AND OWNER_USER_ID IS NOT NULL
AND OWNER_USER_ID = CONSULTANT_RECORD.OWNER_USER_ID;
end loop;
END LOOP;
问题开始发生在评论循环3中,记住我正在开发oracle应用程序门户,所以我无法运行查询优化...我的表也被正确编入索引(如果有人想评论它)。 / p>
此致
PS。没有人用我们的代码版本回复给我..........我仍然在努力解决这个问题: - (
答案 0 :(得分:1)
我认为最好的循环根本就没有循环(当然,如果可以避免的话)。假设vlastday是一个集合,你可以做类似
的事情select COUNT(DISTINCT LOG_NO) as "LOG_COUNT"
FROM DMS_CRM.TBL_DMS_SERVICE_REQUESTS_HIST
INNER JOIN
(
SELECT lpad(to_char(t.COLUMN_VALUE ),2,'0') as x
from table(vlastday)t
)a ON (TO_CHAR(HIST_DATE_TIME_STAMP, 'DD') = a.x)
WHERE LOG_STATUS = 'Resolved'
AND TO_CHAR(HIST_DATE_TIME_STAMP, 'MONTH,YYYY') = TO_CHAR(SYSDATE, 'MONTH,YYYY')
AND OWNER_USER_ID IS NOT NULL
AND OWNER_USER_ID = CONSULTANT_RECORD.OWNER_USER_ID
GROUP BY a.x;
然后取决于你的任务,你需要摆脱GROUP BY
所以你可以select into
,或者在这个变量中声明一组数字和BULK COLLECT
。
另外,我从问题中看到的,你可以为Loop2做同样的事情,所以你不会有循环......