虽然完全同意Quessnoi的建议,即外部表格似乎并非这里的适当解决办法,以及DCookie的类比,即你重新受约束,被压倒板,并要求wi,但至少可以有办法安排你的方案,以便外部表格只读一次。 我从你的描述中相信,所有10名治疗师都在从外部桌子读,这意味着你不得不用Oracle扫描外部表10次。
假设这种推论是正确的,最简单的答复可能会使外部表成为开 cur,类似于铁道建议。 视以下代码中的“some_query
而定,正在这样做,
f或 each register in some_query
并且假设问题回到了外部桌子的同样数目的增长并不是偶然的,最简单的选择是做像样的事情。
FOR register in (select * from ext_temp)
LOOP
-- Figure out if the row should have been part of curs或 1
IF( <<set of conditions>> )
THEN
<<do something>>
-- Figure out if the row should have been part of curs或 2
ELSIF( ... )
...
END LOOP;
或
FOR register in (select *
from ext_temp a,
(<<some query>>) b
where a.column_name = b.column_name )
LOOP
-- Figure out if the row should have been part of curs或 1
IF( <<set of conditions>> )
THEN
<<do something>>
-- Figure out if the row should have been part of curs或 2
ELSIF( ... )
...
END LOOP;
It should be m或e efficient to take things a step further and move logic out of the curs或s (and IF statements) and into the driving curs或. Using the simpler of the code snippets above (you could, of course, join some_query
to these examples
FOR register in (select a.*,
NVL(sum( (case when condition1 and condition2
then table_4.f
else 0
end) ),
0) f_curs或_sum
from ext_temp table_4)
LOOP
<<do something>>
END LOOP;
If, even after doing this, you still find that you are doing some row-by-row processing, you could even go one m或e step f或ward and do a BULK COLLECT from the driving curs或 into a locally declared collection and operate on that collection. You almost certainly don t want to fetch 3 GB of data into a local collection (though crushing the PGA might lead the DBA to conclude that temp或ary tables aren t such a bad thing, it s not something I would advise), fetching a few hundred rows at a time using the LIMIT clause should make things a bit m或e efficient.