Oracle函数题

Examine this function:

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;

 


Which statement will successfully invoke this function in SQL *Plus?(哪种叙述在SQL*Plus中能成功调用这个函数?)
A. SELECT CALC_PLAYER_AVG(PLAYER_ID)
FROM PLAYER_BAT_STAT;
B. EXECUTE CALC_PLAYER_AVG(31);
C. CALC_PLAYER(‘RUTH’);
D. CALC_PLAYER_AVG(31);
E. START CALC_PLAYER_AVG(31)
Answer: A
Incorrect Answers(不正确的答案)
B. You can't call a function in this way, in this way you can call a procedure, because function must return a

你不能用这种方法调用一个函数,你能用这种方法调用一个过程,因为函数必须返回一个
value, to call a function using EXECUTE command you should declare a bind variable using the

值,调用函数使用EXECUTE(执行)命令 你可以声明一个绑定的变量使用这个
VARIABLE command then assign the value returned from the function to this variable, in the following

变量命令然后从返回的这个变量的函数分配这个值,用下面的方法
way:
SQL> VARIABLE v_get_value NUMBER
SQL> EXECUTE :v_get_value := CALC_PLAYER_AVG(31)
PL/SQL procedure successfully completed.
SQL> PRINT v_get_value
V_GET_VALUE
-----------
1
C. Again this way can't be use for calling a function in PL/SQL block because the function return a value

再次这个方法不能从PL/SQL块中调用函数因为这个函数返回一个值
and this values must be assigned to PL/SQL variable or to bind variable. Like this

并且这个值必须分配给PL/SQL或者绑定变量。想这样
DECLARE
v_get_from_fn NUMBER;
BEGIN
v_get_from := CALC_PLAYER_AVG(31);
END;

/
D. Same as C.(同C的回答)
E. START is use to execute a script.(START是用于执行一个脚本)

转载于:https://www.cnblogs.com/siyunianhua/p/3498808.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值