-2
         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;
4

1 回答 1

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
于 2013-03-26T12:42:00.923 回答