PL/SQL使用记录

CREATE OR REPLACE FUNCTION USER_EXP_TIME_FUN(iExpTime IN NUMBER)
RETURN NUMBER
IS
iExpMin number:=trunc(iExpTime/60);
iLevel number:=0;
iNowUpExp number:=0;
iLastUpExp number:=2*60;
iCheckLevelExp number:=0;
iNextLevelExp number:=0;
BEGIN
    IF iExpMin < 120 THEN 
       iLevel:=1;
    ELSE
      FOR i IN 1..100 LOOP
          iNowUpExp:=iLastUpExp+(i-1)*120;
          iCheckLevelExp:=iCheckLevelExp+iNowUpExp;
          IF iExpMin >= iCheckLevelExp THEN
              iNextLevelExp:=iCheckLevelExp+iNowUpExp+i*120;
              IF iExpMin < iNextLevelExp THEN
                iLevel:=i+1;
              END IF;
          END IF;
          iLastUpExp:=iNowUpExp;
      END LOOP;
    END IF;
    return iLevel;
END;
/

CREATE OR REPLACE PROCEDURE daily_rank_pro IS
 type rc is ref cursor;
 money_rank_cur rc;
 integral_rank_cur rc;
 exp_time_rank_cur rc;
 competition_rank_cur rc;
 competition_expect_num number;
 competition_level_id number;
 rank_user_name varchar2(20);
 rank_result number;
 rank_count number:=1;
BEGIN
 delete from user_rank;
 open money_rank_cur for select aa.user_name user_name , (aa.money + aa.bank_money) money from ((select user_name , money , bank_money from users t where t.vip_type = 96 and t.money + t.bank_money >= 2000000 order by money + bank_money desc) aa) where rownum <= 10;
 loop
      fetch money_rank_cur into rank_user_name, rank_result;
      exit when money_rank_cur%notfound;
      insert into user_rank values(user_rank_seq.nextval, rank_user_name, rank_count, 0, rank_result);
      rank_count:=rank_count+1;
 end loop;
 close money_rank_cur;
 rank_count:=1;

 open integral_rank_cur for select aa.user_name user_name , (aa.integral + aa.bank_integral) integral from ((select user_name , integral , bank_integral from users t where t.vip_type = 96 and t.integral + t.bank_integral >= 50000 order by integral + bank_integral desc) aa) where rownum <= 10;
 loop
      fetch integral_rank_cur into rank_user_name, rank_result;
      exit when integral_rank_cur%notfound;
      insert into user_rank values(user_rank_seq.nextval, rank_user_name, rank_count, 1, rank_result);
      rank_count:=rank_count+1;
 end loop;
 close integral_rank_cur;
 rank_count:=1;

 open exp_time_rank_cur for select aa.user_name user_name , aa.exp_time exp_time from ((select user_name , exp_time  from users t where t.vip_type = 96 order by exp_time desc) aa) where rownum <= 10;
 loop
      fetch exp_time_rank_cur into rank_user_name, rank_result;
      exit when exp_time_rank_cur%notfound;
      insert into user_rank values(user_rank_seq.nextval, rank_user_name, rank_count, 2, USER_EXP_TIME_FUN(rank_result));
      rank_count:=rank_count+1;
 end loop;
 close exp_time_rank_cur;
 rank_count:=1;

 select EXPECT_NUM, COMPETE_LEVEL_ID into competition_expect_num, competition_level_id from competition_game_log c where c.EXPECT_NUM = (select max(EXPECT_NUM) from competition_game_log where game_id = 121);
 open competition_rank_cur for select pc.user_name,pc.duel_integral from previous_competition pc where pc.expect_num = competition_expect_num and  pc.compete_level_id = competition_level_id and pc.game_id = 121 and pc.emiction <= 10  order by pc.emiction;
 loop
   fetch competition_rank_cur into rank_user_name, rank_result;
   exit when competition_rank_cur%notfound;
   insert into user_rank values(user_rank_seq.nextval, rank_user_name, rank_count, 3, rank_result);
   rank_count:=rank_count+1;
 end loop;
 close competition_rank_cur;
END;
/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值