+ -
当前位置:首页 → 问答吧 → oracle批量绑定问题求教

oracle批量绑定问题求教

时间:2011-12-13

来源:互联网

今天在写存储过程的时候碰到了一个问题,希望大神们给我看看,
由于是银行搞开发,源代码没法拿下来,我在这里基本简单写一下:
首先:我建立两个集合
type loan_card_no_type is table of ma_loan_card.loan_card_no%type
index by binary_integer;
type loan_date_type is table of varchar2(10)
index by binary_integer;

my_loan_card_no loan_card_no_type;
my_loan_date loan_date_type;

然后对数据进行批量绑定select:
select a.loan_card_no,to_char((b.loan_date-1),'YYYY-MM-DD') bulk collect
into my_loan_card_no,my_loan_date
from ma_loan_card where ....;
--大致就是这样,字段是这么取的,用时差不多20秒左右,表中有50万条数据
批量绑定以后,my_loan_card_no 和ma_loan_date中差不多有9万条记录:

问题主要在这里,在update的时候巨慢:
forall i in 1..my_loan_card_no.count
update acc_loan_card set beg_date=my_loan_date(i),valid_flag='1'
where loan_card_no=my_loan_card_no(i) and valid_flag='0';
--acc_loan_card 这个表中也就50万条记录左右
然后在跑存储过程跑了四五十分钟还没跑完,平时用游标一条条处理这个时间都能出来了,我郁闷了。。。。

希望大神给我解惑。非常感谢!

作者: yangbinnuaaa   发布时间: 2011-12-13

为什么要用数组中间倒一下呢,直接光标得了罢。

作者: LuiseRADL   发布时间: 2011-12-14

不要用游标,游标太慢了

select a.loan_card_no,to_char((b.loan_date-1),'YYYY-MM-DD') bulk collect
into my_loan_card_no,my_loan_date
from ma_loan_card where ....;

update acc_loan_card set beg_date=my_loan_date(i),valid_flag='1'
where loan_card_no=my_loan_card_no(i) and valid_flag='0';

可以合成一条语句执行更新

作者: java3344520   发布时间: 2011-12-14

热门下载

更多