create or replace function calc_player_avg
(v_id IN player_bat_stat.player_id%type)
return number
is
v_avg number;
begin
select hits / at_bats
into v_avg
from player_bat_stat
where player_id = v_id;
return (v_avg);
end;
调用包含“执行”语句,但此处以下语句标记为错误:
Execute calc_player_avg(31);
正确的是:
select calc_palyer_avg(player_id) from player_bat_stat;
答案 0 :(得分:0)
首先是错误的,因为对象是一个函数,所以你需要一个变量来捕获返回值。
SQL> execute calc_player_avg(31);
BEGIN calc_player_avg(31); END;
*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00221: 'CALC_PLAYER_AVG' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
SQL> var avg number;
SQL> execute :avg := calc_player_avg(31);
PL/SQL procedure successfully completed.
SQL> print avg
AVG
----------
.4