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万条记录左右
然后在跑存储过程跑了四五十分钟还没跑完,平时用游标一条条处理这个时间都能出来了,我郁闷了。。。。
希望大神给我解惑。非常感谢!
由于是银行搞开发,源代码没法拿下来,我在这里基本简单写一下:
首先:我建立两个集合
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';
可以合成一条语句执行更新
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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28