l_sql_stmt :=
INSERT INTO WXK_TEMP_TERM_DATA
(
GROUP_TERM_ID,
PARAMETER_ID,
TYPE_DISTRICT,
TYPE_NAME,
VALUE
)
select c.id GROUP_TERM_ID,
d.id PARAMETER_ID,
e.id TYPE_DISTRICT,
trim(concat(trim(a.term_type),trim(a.term_code))) TYPE_NAME,
round(f.value,2)
from CM_bill_TERM_SALE_DETAIL a,
CM_BILL_TERM_SALE_IDNO b,
cm_bill_term_agent c,
cm_stat_parameter d,
cm_bill_district e,
CM_TEMP_IDNOINFO f,
dm_dcustmsg_200912 g
where a.bill_cycle_id=200912
and c.bill_cycle_id=a.bill_cycle_id
and e.bill_cycle_id=a.bill_cycle_id
and b.bill_cycle_id=a.bill_cycle_id
and trim(f.id_no)=trim(b.id_no)
and trim(b.id_no)=trim(g.id_no)
and trim(a.mobile_no)=trim(b.phone_no)
and trim(a.group_id)=trim(c.group_id)
and d.code=decode(nvl(g.sm_code,null),'dn','3872','qq',
'3873','3871')
and trim(a.district_name)=trim(e.name)
and (months_between(to_date('200912','yyyymm'),
to_date(to_char(a.IMPORTED_TIME,'yyyymm'),'yyyymm'))+1)<=36;
EXECUTE IMMEDIATE l_sql_stmt
USING
l_bill_cycle_id,
l_bill_cycle_str;