I need to calculate percentage and accumulate it from every game in. I have to parameters p\_percentage which is gonna be variable and parameter p\_top is also variable and his task is when p\_top is satisfied then do something (update or insert) . I get lost here in loop . Is it better to do loop or fetch into v\_percentage. And Am I doing it right ?
Thanks

```
    CREATE OR REPLACE FUNCTION "jackpot" 
     (p_percentage number
     ,p_top number,
     p_player number,
     p_party_id number
     )
     RETURN NUMBER
    declare           
        Cursor c1 is                                                
            select p_percentage/game_in *100 into v_percentage from game
            where player_id = p_player ;
            rw c1%rowtype;
        v_top number;
        v_percentage number;
        BEGIN 
            open c1;
                 FOR i IN c1                        
                 while v_percentage <= p_top
                     LOOP                               
                     v_percentage:=v_percentage+v_percentage;       
                     end loop; 
                --update something
close c1;
            return v_percentage;
        END;
    end;

```

> 
> EDIT
> 
> 
> 

```
create or replace PROCEDURE super_six_jackpot (
      i_party_id          IN       NUMBER,
      i_jackpot_limit      IN       NUMBER,
      i_jackpot_perc       IN       NUMBER,
      o_pot_size           OUT      NUMBER
   )
   IS
      p_username              VARCHAR2(100);
      p_party_id              number;
      pot_perc                NUMBER;
      pot_size                NUMBER;
      parent_aff              NUMBER;
      ret_pot_size            NUMBER;
      pom                     weak_cur;
   BEGIN
        SELECT  c.party_id, p.aff_id
        into p_party_id, parent_aff
        FROM   casino_users c,pot_by_aff p
       WHERE   c.parent_id = p.aff_id
         AND   c.parent_id = :i_party_id;

        SELECT total
                        INTO   pot_perc
              FROM   (
                SELECT SUM( i_jackpot_perc/game_in * 100 ) OVER ( ORDER BY ROWNUM ) AS total
                FROM   game_record
                WHERE  party_id = p_party_id
                ORDER BY total DESC
              )
              WHERE total <= i_jackpot_limit
              AND   ROWNUM = 1;
                         EXECUTE IMMEDIATE 'UPDATE pot_by_aff
                                 SET bingo_jackpot_size = NVL (total, 0) 
                             WHERE aff_id = :parent_aff
                         RETURNING pot_size
                             INTO :ret_pot_size'
                     USING     parent_aff,
                           OUT ret_pot_size;      
         BEGIN
            OPEN pom FOR 'SELECT bingo_jackpot_size
                            FROM pot_by_aff
                           WHERE aff_id = :parent_aff' 
                           USING parent_aff;
            FETCH pom
             INTO ret_pot_size;
            CLOSE pom;
         END;
      o_pot_size      := ret_pot_size;

      END super_six_jackpot;

```