当前位置: 代码迷 >> Oracle开发 >> 存储过程循环 大家帮忙调上
  详细解决方案

存储过程循环 大家帮忙调上

热度:58   发布时间:2016-04-24 07:14:42.0
存储过程循环 大家帮忙调下
create or replace procedure tj_count_coupon

as
  a  number;
  v_limitid number;
  v_limitname varchar2;
  v_merchantname varchar2;

Begin
     select count(*) into a
               from couponinfo t
               left join coupon_merchant t1 on t.coupon_id = t1.product_id
               left join merchant t2 on t1.merchant_id = to_char(t2.merchant_id)
                                    and t1.product_type = 1
              where to_date(t.end_date, 'yyyy-mm-dd HH24:mi:ss') >= sysdate
                and to_char(t.str_date, 'yyyy-mm-dd HH24:mi:ss' ) <= to_char(sysdate,'yyyy-mm-dd HH24:mi:ss')


      for i in 1...a  loop
      
              select t2.name into v_merchantname,
              t.coupon_id into v_limitid ,
              t.coupon_name into v_limitname
               from couponinfo t
               left join coupon_merchant t1 on t.coupon_id = t1.product_id
               left join merchant t2 on t1.merchant_id = to_char(t2.merchant_id)
                                    and t1.product_type = 1
              where to_date(t.end_date, 'yyyy-mm-dd HH24:mi:ss') >= sysdate
                and to_char(t.str_date, 'yyyy-mm-dd HH24:mi:ss' ) <= to_char(sysdate,'yyyy-mm-dd HH24:mi:ss')
         where rownum=i
         
         insert into count_coupon((id, coupon_id, coupon_name, rec_date, down_count, merchant_name) values
                    (SEQ_count_coupon_ID.Nextval,v_limitid,v_limitname,to_char(sysdate,'yyyy-mm-dd'),
                     (select count(*) as t from user_coupon where coupon_id=v_limitid  and  to_char(reg_date,'yyyy-MM-dd')=to_char(sysdate,'yyyy-mm-dd')),
  相关解决方案