今天在写存储过程的时候碰到了一个问题,希望大神们给我看看,
由于是银行搞开发,源代码没法拿下来,我在这里基本简单写一下:
首先:我建立两个集合
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万条记录左右
然后在跑存储过程跑了四五十分钟还没跑完,平时用游标一条条处理这个时间都能出来了,我郁闷了。希望大神给我解惑。非常感谢!
解决方案 »
- 就是 数据库中的 资源问题 如 图片,视屏
- linux下oracle监听端口响应慢,求解决方法
- oracle监听的问题
- oracle10导DMP出错(2270)求解决办法1
- oracle中是否可以定义“表变量”?如果有,那怎样定义呢?谢谢
- 欢迎大家来讨论数据库接口技术.
- 请问在哪里可以找到Oracle J2EE 服务器 For windows的安装程序?
- 在oracle里,什么是“事件”,“作业”,“报告”?请高手帮我深入理解一下?
- 如何将acess库转为oracle数据库,马上给分!
- 存储过程编码找出物料编码为“1”或“5”开头的物料对应的成本对象/产品为“8”或字母开头的成品关系;一共需出具2014-2017年4年对应清单
- RAC自动切换数据库问题
- SQL求教
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';可以合成一条语句执行更新
from a.loan_card_no,a.beg_date,a.valid_flag,to_char((b.loan_date-1),'YYYY-MM-DD') as set_date
from ma_loan_card a
where ...
) t
SET beg_date=set_date,valid_flag='1'
必要时加:/*+bypass_ujvc+*/