1

有人可以指出我做错了什么吗?我正在尝试根据下表创建一个排名程序:

在此处输入图像描述

这是代码:

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;
/
4

1 回答 1

1

试试这个:

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;
/
于 2013-11-03T02:57:35.283 回答