---授权
GRANT SELECT ANY TABLE TO KMPRODUCT WITH ADMIN OPTION;
create or replace procedure p_insert_coupon is
couponGrantId coupon_grant.coupon_grant_id%TYPE;
couponId coupon_grant.coupon_id%TYPE;
couponIssuingId coupon_grant.coupon_issuing_id%TYPE;
loginId number(22);
day_num number(22);
v_index number(10);
startTime VARCHAR2(32);
endTime VARCHAR2(32);
--定义获取所有时代用户id的游标
cursor c_loginId is
select n_login_id from KMUSER.ERA_INFO;
begin
v_index := 0;
select EXTRACT(DAY FROM SYSDATE) into day_num from dual;
if day_num = 18 then
couponId := 12728;
couponIssuingId := 9909;
startTime := '2015-06-18 00:00:01';
endTime := '2015-06-19 00:00:01';
end if;
if day_num = 19 then
couponId := 12729;
couponIssuingId := 9910;
startTime := '2015-06-19 00:00:01';
endTime := '2015-06-20 00:00:01';
end if;
if day_num = 20 then
couponId := 12730;
couponIssuingId := 9911;
startTime := '2015-06-20 00:00:01';
endTime := '2015-06-21 00:00:01';
end if;
for v_loginId in c_loginId loop
for i in 1 .. 4 loop
INSERT INTO coupon_grant c
(coupon_grant_id,
coupon_id,
custom_id,
coupon_status,
grant_creattime,
grant_type,
starttime,
endtime,
coupon_issuing_id,
act_status,
grant_acttime)
VALUES
(seq_app_couponpgrant.nextval,
---规则id
couponId,
---会员id
v_loginId.n_Login_Id,
3,
sysdate,
11,
to_date(startTime, 'yyyy-mm-dd hh24:mi:ss'),
to_date(endTime, 'yyyy-mm-dd hh24:mi:ss'),
--发放设置7982
couponIssuingId,
1,
sysdate);
end loop;
v_index := v_index + 1;
if mod(v_index,5000)=0 then
commit;
end if;
end loop;
commit;
end p_insert_coupon;