Question

Can someone point out what I'm doing wrong? I'm trying to create a ranking procedure based on the following tables:

enter image description here

Here is the code:

create or replace procedure rank
(para_userid IN number, USERID IN number)
is
     rank number;
     v_userid number;
begin
     v_userid := &USERID;
     select v_userid, sum(decode(a.rank, 'SU', 25, 'EX', 9, 'VG', 5, 'G', 3, 'F',1) * b.tokens) / sum(b.tokens)
into rank
from a.GameID = b.GameID
where para_userid = v_userid;
return rank;
end;



declare 
x number;
begin
x:=rank(&USERID);
DBMS_OUTPUT.PUT_LINE('User Ranking is: '||x);
end;
/
Was it helpful?

Solution

Try this:

CREATE OR REPLACE FUNCTION f_rank (USERID IN number) RETURN NUMBER DETERMINISTIC IS
     nRank number;
BEGIN
    SELECT SUM(DECODE(a.rank, 'SU', 25, 'EX', 9, 'VG', 5, 'G', 3, 'F',1) * b.tokens) / SUM(b.tokens)
    INTO nRank
    FROM a JOIN b ON a.GameID = b.GameID
    WHERE 
        para_userid = USERID;
    RETURN nRank;
END f_rank;



DECLARE
    x number;
BEGIN
    x := f_rank(&USERID);
    DBMS_OUTPUT.PUT_LINE('User Ranking is: '||x);
END;
/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top