我有这个程序:
create or replace procedure check_max_game_rule_test (i_player_id IN NUMBER,i_max_games IN NUMBER, i_err_code OUT number)
is
v_fixid number;
v_count_fixid number;
max_games_violation exception;
cursor c1 is
SELECT ti.fixid,count(ti.fixid)
FROM BUS_SESSION BS,
CASINO_USERS CUP,
TICKET_ITEMS TI
WHERE BS.PARTY_ID = 4356
AND TI.BUS_SESSION_SESSION_ID = BS.SESSION_ID
AND NVL(BS.SESSION_CLOSE,'N') = 'N'
and CUP.parent_id = BS.AFF_ID
AND BS.SESSION_TYPE = 'TICKET SESSION'
group by TI.FIXID;
r1 c1%ROWTYPE;
begin
open c1;
loop
fetch c1 into v_fixid,v_count_fixid;
if v_count_fixid > i_max_games
then
raise max_games_violation;
end if;
end loop;
close c1;
end ;
程序应该计算相同的fixid并将其与i_max_games进行比较,如果该fixid的计数大于i_max_games,则引发异常..
现在我遇到符号c1
有人可以帮我解决这个问题吗?这是用于获取和比较fixid逻辑的光标吗?
答案 0 :(得分:2)
您不需要CURSOR
循环。使用单个选择并根据总计数引发异常。另外,使用ANSI JOIN
s。
create or replace procedure check_max_game_rule_test (i_player_id in number,
i_max_games in number,
i_err_code out number)
is
v_count_fixid number;
max_games_violation exception;
begin
select count(*)
into v_count_fixid
from (
select 1 FROM bus_session bs
join casino_users cup
on cup.parent_id = bs.aff_id
join ticket_items ti
on ti.bus_session_session_id = bs.session_id
where bs.party_id = 4356
and nvl(bs.session_close, 'N') = 'N'
and bs.session_type = 'TICKET SESSION'
group by ti.fixid
having count(ti.fixid) > i_max_games );
if v_count_fixid > 0 then
raise max_games_violation;
end if;
end;
/