哪个语句将成功调用该函数? [关闭]

Posted

技术标签:

【中文标题】哪个语句将成功调用该函数? [关闭]【英文标题】:Which statement will successfully invoke the function? [closed] 【发布时间】:2013-03-26 11:49:48 【问题描述】:
         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;

【问题讨论】:

【参考方案1】:

第一个是错误的,因为对象是一个函数,所以你需要一个变量来捕获返回。

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

【讨论】:

哦,是的!函数需要返回值。我怎么能忘记这么重要的事实。谢谢:)

以上是关于哪个语句将成功调用该函数? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章

点击关闭窗口,确实是否关闭,是调用哪个函数。

Javascript,对象,函数和案例语句问题[关闭]

标准文件IO详解---fclose函数详解

从 update 语句成功调用函数,但从 select 语句调用时出错

close函数

调用栈