简体   繁体   English

使用限制问题获取批量收集 (Oracle)

[英]fetch bulk collect with limit question (Oracle)

Good day!再会! Environment : Oracle 12.2 EE 64-bit.环境:Oracle 12.2 EE 64 位。

Suppose I have a code:假设我有一个代码:

Declare
 Rc sys_refcursor;
Type mt is varchar2(25);
Type_mt_t is table of mt;
Mem_tbl mt_t;
begin
Open rc for
Select a.a from tbl a
Where a.path =’1’ 
 And not exists
(select 1 from tbl b
 Where b.path=’-1’
 And b.a = a.a);

Loop 
 Fetch rc bulk collect into mem_tbl limit 500;
 Exit when …
End loop;
End;

The question is – does Open rc clause prefetch all data at once , preliminary, or ref cursor re-scans every time it's called inside “fetch loop”?问题是——Open rc子句是一次预取所有数据,还是每次在“提取循环”中调用时重新扫描参考游标? I'm about read consistency and possible (undesirable of course) cursor mutation during fetch bulk collect limit loop.我是关于读取一致性和可能(当然是不希望的)在获取批量收集限制循环期间的游标突变。

Any help would be very appreciated.任何帮助将不胜感激。

TIA, Andrew. TIA,安德鲁。

No. The moment you open a cursor in Oracle, the results are "set in stone" as of that moment in time.不会。您在 Oracle 中打开游标的那一刻,结果即刻“一成不变”。 That does not mean we actually go an read all of the data - we only need to read it as you fetch.这并不意味着我们实际上会读取所有数据 - 我们只需要在您获取时读取它。

Of course, that raises the question - what happens when we fetch and chance upon some data that someone else has changed since the cursor was opened?当然,这提出了一个问题——当我们获取并偶然发现自游标打开后其他人已更改的某些数据时会发生什么? (because we don't block anyone whilst we read). (因为我们在阅读时不会阻止任何人)。

We use internal "undo" information to reverse out those changes (in memory) so that we can give the caller (you) a version of the data as it was at the time your query started.我们使用内部“撤消”信息来撤销这些更改(在内存中),以便我们可以为调用者(您)提供查询开始时的数据版本。

You'll never see those changes that were committed after your query started - you always get a clean, consistent set of rows.您永远不会看到在查询开始后提交的那些更改——您总是会得到一组干净、一致的行。

If you want a longer, more detailed coverage of this, I spend around 20mins on it in this podcast如果您想要对此进行更长时间、更详细的报道,我在这个播客中花了大约 20 分钟

https://open.spotify.com/episode/3J8FbfQrKFyVAr7F1Ja0gN https://open.spotify.com/episode/3J8FbfQrKFyVAr7F1Ja0gN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM