Oracle批量收集问题
我在批量收集 SQL 时遇到了一些小问题,希望您能帮忙解决。
使用以下代码:
declare
cursor c1
is
select customer,product
from products;
type type_cust is table of products.customer%type;
type type_prod is table of products.product%type;
v_array_cust type_cust;
v_array_prod type_prod;
begin
open c1;
loop
fetch c1
into v_array_cust, v_array_prod
limit 1000;
exit when c1%notfound;
for i in 1..v_array_cust.count
loop
--Do some processing here.
end loop;
end loop;
end;
/
游标 c1 返回 53166 行。
但是,代码处理了 53000 行,然后结束。似乎在检索最后 166 条记录时出现了某种故障。
如果找到的记录少于 1000 条,提取会返回 %notfound 吗?我应该将出口移到循环的末尾吗? (我打算尝试这个,但它在一段代码中很深,需要 3 个小时才能到达故障点。)
提前致谢。
I'm having a little issue with a piece of bulk collect sql that I was hoping you could help out with.
With the following code:
declare
cursor c1
is
select customer,product
from products;
type type_cust is table of products.customer%type;
type type_prod is table of products.product%type;
v_array_cust type_cust;
v_array_prod type_prod;
begin
open c1;
loop
fetch c1
into v_array_cust, v_array_prod
limit 1000;
exit when c1%notfound;
for i in 1..v_array_cust.count
loop
--Do some processing here.
end loop;
end loop;
end;
/
The cursor c1 returns 53166 rows.
However, the code process 53000 rows and then ends. It seems that when going to retrieve the last 166 records there is some sort of failure.
Will the fetch return %notfound if it find's less than 1000 records? Should I move the exit to the end of the loop? (I am going to try this but it is deep in a piece of code that take 3 hours to get to the failure point.)
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,比我已经做过的更好的谷歌搜索给了我答案,你不应该使用 %notfound 进行限制。
请查看此处了解说明。
OK, well a better bit of googling than I'd already done gave me the answer you shouldn't use %notfound with limit.
Check here for an explanation.
仅供参考,这里有一个使代码正确运行的简单更改:
Just for reference, here's one simple change to make the code run correctly:
很抱歉我是这么说的,但是确认!光标!...从您编写此内容的方式看来,您来自线性编程背景。您是否考虑过基于集合的解决方案?
Sorry to be the one to say it, but ack! cursors!...the way you've written this appears you've come from a linear programming background. Have you considered a set based solution to this?