需求:我們需要從另外乙個資料庫每天定時備份啟用的資料到本地資料庫
create
orreplace
procedure p_dealer_active_report(pv_date in
varchar2)is
/*** 統計日啟用報表
*/pn_id number
;--主鍵
pv_createdate varchar2(20
);--建立時間
pv_routeid varchar2(50
);--渠道編碼
cursor activationlist is
select t.*
from t_dealer_activation_list t
where substr(v_act_date,1,
8)= pv_createdate ;
--統計某天的啟用量與產品資訊
cursor orderlist is
select
count
(l.v_routeid) n_num,l.v_routeid,
t.v_big_type,b.v_prod_big_name,t.v_small_type,y.v_small_name,l.v_prod_code,t.v_prod_name,
v_routename ,v_routetype, v_routetypename,v_level,v_levelname,v_area,
v_areaname,v_subarea,v_subareaname,v_managerid,v_managername,
substr(v_act_date,1,
4)||
'/'|| substr(v_act_date,5,
2)||
'/'|| substr(v_act_date,7,
2) v_finishtime,
substr(v_act_date,1,
6) v_month
from t_dealer_activation_list l , t_dealer_product t , t_dealer_prod_type y, t_dealer_prod_big b,v_dealer_dict_route v
where substr(v_act_date,1,
8)=pv_createdate
and l.v_prod_code= t.v_prod_code(+)
and l.v_routeid= v.v_routeid(+)
and t.v_small_type=y.v_small_type(+)
and y.v_big_type=b.v_prod_big_code(+)
group
by l.v_routeid,l.v_prod_code,v_routename,v_routetype, v_routetypename,v_level,v_levelname,v_area,
v_areaname,v_subarea,v_subareaname,v_managerid,v_managername,
t.v_big_type,b.v_prod_big_name,t.v_small_type,
y.v_small_name,t.v_prod_name, substr(v_act_date,1,
4)||
'/'|| substr(v_act_date,5,
2)||
'/'|| substr(v_act_date,7,
2),substr(v_act_date,1,
6);
--統計啟用量同步到_dealer_order_prod
cursor prodlistactivation is
select o.v_orderid,l.v_prod_code,
count
(*) n_activation_numfrom t_dealer_prod_list l ,t_dealer_consignment_order o
where o.v_orderid = l.v_orderid
and d_use is
notnull
group
by o.v_orderid,l.v_prod_code;
begin
--輸入引數為空缺省取前一天的日期
if pv_date is
null
then
select to_char(
sysdate-1
,'yyyymmdd'
)into pv_createdate from dual;
else
pv_createdate := pv_date;
endif;
--刪除已有記錄
delete
from t_dealer_activation_list
where substr(v_act_date,1,
8)=pv_createdate;
--刪除日啟用報表的資料
delete
from t_dealer_active_report rwhere to_char(r.d_day,
'yyyymmdd'
)=pv_createdate;
--第一步,同步清單
insert
into t_dealer_activation_list(v_iccid,v_routeid,v_act_date,d_import)
select hd.iccid,hd.simdealerid routeid,hd.timeenteractive,
sysdate
from tb_dw_subscriber_his_day hd ,t_dealer_dict_route r
where hd.simdealerid =r.v_routeid
and substr(hd.timeenteractive,1,
8)= pv_createdate
and hd.simdealerid is
notnull;
--第二步,補充完成啟用清單
for o in activationlistloop
--如果在分銷系統銷售的,補充產品資訊
update t_dealer_activation_list l
set l.v_prod_code = (
select v_prod_codefrom t_dealer_prod_list t where t.v_iccid=o.v_iccid)
where l.v_iccid=o.v_iccid;
--回填啟用時間
update t_dealer_prod_list l
set l.d_use =to_date(o.v_act_date,
'yyyymmddhh24miss')
where l.v_iccid=o.v_iccid;
commit;
endloop;
--第三步,統計日啟用報表
--新增當天啟用記錄
for o in orderlistloop
select seq_active_report.nextval into pn_id from dual;
pv_routeid := o.v_routeid;
insert
into t_dealer_active_report(
n_id,v_month,d_day,v_routeid,v_big_type,v_small_type,v_small_name,v_prod_code,v_prod_name,n_num,
v_routename,v_managerid,v_managername,v_areaid,v_areaname,v_levelid,v_levelname,v_typeid,v_typename,d_act)
values(
pn_id,
o.v_month,
to_date(o.v_finishtime,
'yyyy/mm/dd'),
o.v_routeid,
o.v_big_type,
o.v_small_type,
o.v_small_name,
o.v_prod_code,
o.v_prod_name,
o.n_num,
o.v_routename,
o.v_managerid,
o.v_managername,
o.v_area,
o.v_areaname,
o.v_level,
o.v_levelname,
o.v_routetype,
o.v_routetypename,
sysdate );
commit;
endloop;
--啟用量同步到_dealer_order_prod
for o in prodlistactivationloop
update t_dealer_order_prod set n_activation_num =o.n_activation_num
where v_orderid=o.v_orderidand v_prod_code =o.v_prod_code;
commit;
endloop;
end p_dealer_active_report;
end p_dealer_active_report
oracle 儲存過程demo
個人留作筆記 create or replace procedure ykt exception p jyrq in varchar2 p jysj in varchar2,p kh in varchar2,p wid in varchar2,p xh in varchar2 p jyje in n...
oracle儲存過程demo分享
1.定義儲存過程 定義 create or replace procedure proc01 as n int 注意定義變數後面要加分號 begin select count into n from emp dbms output.put line 員工表中有 n 條記錄!end 呼叫 declar...
儲存過程簡單demo
二 儲存過程demo 儲存過程是儲存在資料庫中執行某種特定功能的程式,其中包含一條或多餘sql語句。儲存過程是一段sql語句集,在編寫完成這段sql語句集,編譯一次並以可執行形式儲存,呼叫它時在資料庫記憶體空間中執行。儲存過程呼叫快速而有效。可執行 會自動快取並在使用者之間共享。這降低了記憶體需求和...