有人可以指出我做错了什么吗?我正在尝试根据以下表创建排名过程:
以下是代码:
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;
/
答案 0 :(得分: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;
/