- 论坛徽章:
- 0
|
几十条SQL语句如何在存储过程中优化
我以前聚合某张明细表,通过了以下几十条语句来处理,现在想改成效率高、速度快的存储过程,应该如何处理呢,请各位提供意见和建议,谢谢,若想单独和我详谈,QQ:11774383,多谢了:
--取帐号属性
create table node_cust_rela_detail_tmp nologging as
select distinct a.node_no,a.operator_no,a.custom_no,
b.custom_name,b.attr_2,b.attr_3,b.cate_1,b.cate_2,
b.cate_4,b.cate_5,
a.account_no,a.acc_type,a.ratio
from cust_base_cate_info b,oper_cust_acc_rela a
where a.custom_no = b.custom_no
and a.valid_flag='0' and b.valid_flag='0' ;
create index node_cust_detail_tmp_i0 on node_cust_rela_detail_tmp(acc_type,account_no) nologging ;
-- 取储蓄账户余额等信息
create table cust_base_deposit_tmp1 nologging as
select a.*,b.currency_type,b.subject_no,'S'||b.account_type deposit_type,b.area_code,b.open_date,nvl(b.close_date,'NULL') close_date ,
b.acc_bal,b.y_avg_bal,0 last_bal,0 last_avg
from node_cust_rela_detail_tmp a,sav_account_unchange b where a.acc_type='1'
and a.account_no = b.account_no
and b.currency_type not like '9%'
and b.sort_type = '0'
and b.valid_flag = '0' ;
-- 取外币折算成人民币数据
insert into cust_base_deposit_tmp1 nologging
select a.*,b.currency_type,b.subject_no,'S'||b.account_type deposit_type,b.area_code,b.open_date,nvl(b.close_date,'NULL') close_date ,
b.acc_bal,b.y_avg_bal,0 last_bal,0 last_avg
from node_cust_rela_detail_tmp a,sav_account_unchange b
where a.acc_type='1'
and a.account_no = b.account_no
and b.currency_type = '98'
and b.sort_type = '0'
and b.valid_flag = '0' ;
-- 取会计账户余额等信息
insert into cust_base_deposit_tmp1 nologging
select a.*,b.currency_type,b.subject_no,'A'||b.account_type deposit_type, b.area_code,b.open_date, nvl( b.close_date , 'NULL' ) ,
b.acc_bal,b.y_avg_bal,0,0
from node_cust_rela_detail_tmp a,acc_account_unchange b
where a.acc_type='0'
and a.account_no = b.account_no
and b.currency_type not like '9%'
and b.sort_type = '0'
and b.valid_flag = '0' ;
insert into cust_base_deposit_tmp1 nologging
select a.*,b.currency_type,b.subject_no,'A'||b.account_type deposit_type, b.area_code,b.open_date, nvl( b.close_date , 'NULL' ) ,
b.acc_bal,b.y_avg_bal,0,0
from node_cust_rela_detail_tmp a,acc_account_unchange b
where a.acc_type='0'
and a.account_no = b.account_no
and b.currency_type = '98'
and b.sort_type = '0'
and b.valid_flag = '0' ;
--汇总
create table cust_base_deposit_tmp3 nologging as
select node_no,operator_no,custom_no,custom_name,
attr_2,attr_3,cate_1,cate_2,cate_4,cate_5,
account_no,acc_type,ratio,currency_type,
subject_no,deposit_type,area_code,open_date,close_date,
sum(acc_bal) acc_bal,
sum(y_avg_bal) y_avg_bal,sum(last_bal) last_bal ,
sum(last_avg) last_avg from (
select * from cust_base_deposit_tmp1
union all
select * from cust_base_deposit_tmp2
) group by node_no,operator_no,custom_no,custom_name,
attr_2,attr_3,cate_1,cate_2,cate_4,cate_5,
account_no,acc_type,ratio,currency_type,
subject_no,deposit_type,area_code,open_date,close_date ;
create index cust_base_deposit_tmp_i1 on cust_base_deposit_tmp3(account_no)
nologging ;
--取利息数据
create table cust_dept_int_today nologging as
select account_no,cur_type,sum(y_int_amt) y_int_amt
from sav_dept_detail_int_g
where busi_date='2008-08-17' group by account_no,cur_type ;
insert into cust_dept_int_today nologging
select account_no,cur_type,sum(y_int_amt)
from acc_dept_detail_int_g
where busi_date='2008-08-17' group by account_no,cur_type
insert into cust_dept_int_today nologging
select b.account_no,'98',ROUND(b.y_int_amt*a.rate_stand/100,2)
from acc_febs_exchange_rate a,cust_dept_int_today b
where a.trans_date = '2008-08-17'
and a.cur_type = b.cur_type and a.cur_type != '00' ;
create index cust_dept_int_today_i1 on cust_dept_int_today(account_no,cur_type) nologging ;
-- 最后汇总
create table cust_base_deposit_info nologging as
select a.*,nvl(y_int_amt,0) inter_amt
from cust_base_deposit_tmp3 a,cust_dept_int_today b
where a.account_no=b.account_no(+)
and ( b.cur_type=a.cur_type or b.cur_type is null ); |
|