在以下查询中使用'case'语句的位置?

时间:2017-10-11 16:52:57

标签: sql function case

这是给我的问题陈述:

1

create or replace function disp_player_name (play_id in number)  
return varchar is status_name varchar(100);  
begin  
select country into status_name from player where id=play_id;  
return status_name;  exception  
when no_data_found then status_name := 'No such country'  
return status_name;  
end;/

我应该在哪里使用'case'来打印问题陈述中给出的状态?

1 个答案:

答案 0 :(得分:0)

这绝对看起来像家庭作业,但就在你的SELECT INTO之后。

create or replace function disp_player_name (play_id in number)  
return varchar is status_name varchar(100);  
begin  

select country into status_name from player where id=play_id;  

CASE
            WHEN status_name = 'India' THEN
                status_name := 'Player belongs to India';

END CASE;

return status_name;

exception  
when CASE_NOT_FOUND then status_name := 'No such country'  

return status_name;  
end;/