静态游标
CREATE OR REPLACE PROCEDURE ORDER_TO_HIS(i_beginTime in varchar2, --开始时间
i_endTime in varchar2, -- 结束时间
i_mkt_campaign_id in varchar2 --活动id
) as
--年月表后缀
cursor c_emp is
select b.contact_order_id
from contact_order b
where b.mkt_campaign_id = i_mkt_campaign_id
and b.create_date >= to_date(i_beginTime, 'yyyy/MM/dd HH24:mi:ss')
and b.create_date <= to_date(i_endTime, 'yyyy/MM/dd hh24:mi:ss')
and rownum < 40000;
order_id contact_order.contact_order_id%type;
-- 根据活动 id 开始时间和结束时间取 contact_order表数据 从而找到 contact_result表和contact_push_msg表数据
-- 先插入年月表,然后删除contact_result表和contact_push_msg表数据 最后删除contact_order表数据
-- oauth qiangsw
begin
--打开游标
open c_emp;
begin
loop
fetch c_emp
into order_id;
exit when c_emp%notfound;
-- contact_result
insert into contact_result_201907 value
select * from contact_result a where a.contact_order_id = order_id;
delete from contact_result a where a.contact_order_id = order_id;
-- contact_push_msg
insert into contact_push_msg_201908 value
select * from contact_push_msg where contact_order_id = order_id;
delete from contact_push_msg c where c.contact_order_id = order_id;
-- contact_order
insert into contact_order_201907 value
select * from contact_order where contact_order_id = order_id;
delete from contact_order o where o.contact_order_id = order_id;
end loop;
end;
--关闭游标
close c_emp;
commit;
end;
------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE TASK_TO_HIS(i_beginTime in varchar2, --开始时间
i_endTime in varchar2, -- 结束时间
i_mkt_campaign_id in varchar2 --活动id
) as
--年月表后缀
cursor c_emp is
select b.Contact_Task_Id
from CONTACT_TASK b
where b.mkt_campaign_id = i_mkt_campaign_id
and b.create_date >= to_date(i_beginTime, 'yyyy/MM/dd HH24:mi:ss')
and b.create_date <= to_date(i_endTime, 'yyyy/MM/dd hh24:mi:ss')
and rownum < 50000;
task_id CONTACT_TASK.CONTACT_TASK_ID%type;
-- 根据活动 id 开始时间和结束时间取 contact_task表数据 从而找到 contact_item表和contact_chl_attr_inst表与
-- contact_task_chl表数据
-- 先插入年月表,然后删除contact_result表和contact_push_msg表数据 最后删除contact_order表数据
-- oauth qiangsw
begin
--打开游标
open c_emp;
begin
loop
fetch c_emp
into task_id;
exit when c_emp%notfound;
-- contact_item
insert into contact_item_201907 value
select * from contact_item a where a.contact_task_id = task_id;
delete from contact_item a where a.contact_task_id = task_id;
--游标
declare
cursor C_TASK_CHL IS
select e.contact_task_chl_id
from contact_task_chl e
where e.contact_task_id = task_id;
task_chl_id CONTACT_TASK_CHL.CONTACT_TASK_CHL_ID%TYPE;
begin
open C_TASK_CHL;
loop
fetch C_TASK_CHL
into task_chl_id;
exit when C_TASK_CHL%notfound;
-- contact_chl_attr_inst
insert into contact_chl_attr_inst_201907 value
select *
from contact_chl_attr_inst
where CONTACT_TASK_CHL_ID = task_chl_id;
delete from contact_chl_attr_inst c
where c.contact_task_chl_id = task_chl_id;
-- contact_task_chl
insert into contact_task_chl_201907 value
select * from contact_task_chl where contact_task_id = task_id;
delete from contact_task_chl where contact_task_id = task_id;
end loop;
--关闭游标
close C_TASK_CHL;
end;
-- contact_task
insert into contact_task_201907 value
select * from contact_task where contact_task_id = task_id;
delete from contact_task o where o.contact_task_id = task_id;
end loop;
end;
--关闭游标
close c_emp;
COMMIT;
end;
动态游标
CREATE OR REPLACE PROCEDURE PUSHMSG_TO_HIS1(i_beginTime in varchar2, --开始时间
i_endTime in varchar2 -- 结束时间
) is
type s_cursor is ref cursor; --申明动态游标
v_push_msg s_cursor; --动态游标赋值
pushMsgId contact_push_msg.push_msg_id%type;
psuhSql varchar2(1000);
tabelDate varchar2(100);
-- oauth qiangsw
begin
--打开游标
open v_push_msg for
select b.push_msg_id, to_char(b.create_date, 'yyyyMM') createDate
from contact_push_msg b
where b.create_date > to_date(i_beginTime, 'yyyy/MM/dd HH24:mi:ss')
and b.create_date < to_date(i_endTime, 'yyyy/MM/dd hh24:mi:ss')
and status_cd = '1100'
and rownum < 40000;
--begin
--loop
fetch v_push_msg
into pushMsgId, tabelDate;
while v_push_msg%found loop
psuhSql := 'insert into contact_push_msg_' || tabelDate ||
' value select * from contact_push_msg where push_msg_id =' ||
pushMsgId;
--EXECUTE IMMEDIATE (psuhSql);
delete from contact_push_msg where push_msg_id = pushMsgId;
end loop;
commit;
-- end loop;
--end;
--关闭游标
close v_push_msg;
end;