我正在嘗試編寫一個PL/SQL函數,該函數以玩家的名字作爲參數,並返回在他最喜歡的場館中玩的比賽數量。PL/SQL函數編譯錯誤
如果玩家表中不存在該玩家,則該函數應返回-2。如果玩家存在但他沒有任何最喜歡的體育場,則該函數返回-1。
這是我有:
create or replace function favS(pname varchar2) return number
as
fav_stadium_count number;
begin
select count(case when favstadiums.stadium = matches.stadium then 1 else null end) into fav_stadium_count
from favstadiums
right join players
on favstadiums.player = players.name
outer join matches
on favstadiums.stadium = matches.stadium;
if (count(case when favstadiums.stadium = matches.stadium then 1 else null end) > 0) then
return fav_stadium_count;
end if;
if players.name is null then
return -2;
end if;
if (count(case when favstadiums.stadium = matches.stadium then 1 else null end) < 1) then
return -1;
end if;
end;
但我得到以下編譯錯誤:
Line 9: ORA-00933: SQL command not properly ended
Line 5: SQL Statement ignored
關於如何解決此問題的任何想法?
這裏是數據庫的關係圖,如果有幫助:
(特德)編輯:
create or replace function favS(pname varchar2) return number
as
fav_stadium_count number;
vplayername varchar(100);
begin
select count(case when favstadiums.stadium = matches.stadium then 1 else null end) into fav_stadium_count,
players.name into vplayername
from favstadiums
right join players
on favstadiums.player = players.name
left outer join matches
on favstadiums.stadium = matches.stadium
where name = pname;
if (fav_stadium_count > 0) then
return fav_stadium_count;
end if;
if vplayername is null then
return -2;
end if;
if (fav_stadium_count < 1) then
return -1;
end if;
end;
我不確定這個ERD是否比聲明更容易閱讀。 –
您編輯的查詢語法錯誤。你需要'SELECT value1,value2 INTO variable1,variable2 FROM ...' –