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?

  1. SELECT CALC_PLAYER_AVG(PLAYER_ID) FROM PLAYER_BAT_STAT;

  2. EXECUTE CALC_PLAYER_AVG (31);

  3. CALC_PLAYER (.RUTH.);

  4. CALC_PLAYER_AVG(31);

  5. START CALC_PLAYER_AVG(31)


Correct Option: A

AI Explanation

To determine which statement will successfully invoke the given function in SQL *Plus, let's go through each option:

Option A) SELECT CALC_PLAYER_AVG(PLAYER_ID) FROM PLAYER_BAT_STAT; This option is correct. It successfully invokes the function CALC_PLAYER_AVG by passing the PLAYER_ID column from the PLAYER_BAT_STAT table as the argument. The function will calculate the average for each player.

Option B) EXECUTE CALC_PLAYER_AVG (31); This option is incorrect. The EXECUTE statement is used to execute a stored procedure or anonymous block, not a function. In this case, you should use the SELECT statement to invoke the function.

Option C) CALC_PLAYER (.RUTH.); This option is incorrect. The function name is CALC_PLAYER_AVG, not CALC_PLAYER. Additionally, the argument should be provided as a value, not a string literal. The correct format is CALC_PLAYER_AVG(31).

Option D) CALC_PLAYER_AVG(31); This option is incorrect. Although the function name and argument are correct, you should use the SELECT statement to invoke the function.

Option E) START CALC_PLAYER_AVG(31) This option is incorrect. The START command is used to execute a script file in SQL *Plus, not to invoke a function.

The correct answer is Option A) SELECT CALC_PLAYER_AVG(PLAYER_ID) FROM PLAYER_BAT_STAT. This option successfully invokes the CALC_PLAYER_AVG function by passing the PLAYER_ID column from the PLAYER_BAT_STAT table as the argument.

Find more quizzes: