Examine this code: CREATE OR REPLACE FUNCTION gen_email_name (p_first_name VARCHAR2, p_last_name VARCHAR2, p_id NUMBER) RETURN VARCHAR2 is v_email_name VARCHAR2(19); BEGIN v_email_home := SUBSTR(p_first_name, 1, 1) || SUBSTR(p_last_name, 1, 7) || [email protected] .; UPDATE employees SET email = v_email_name WHERE employee_id = p_id; RETURN v_email_name; END; You run this SELECT statement: SELECT first_name, last_name gen_email_name(first_name, last_name, 108) EMAIL FROM employees; What occurs?

  1. Employee 108 has his email name updated based on the return result of the function.

  2. The statement fails because functions called from SQL expressions cannot perform DML.

  3. The statement fails because the functions does not contain code to end the transaction.

  4. The SQL statement executes successfully, because UPDATE and DELETE statements are ignoring in stored functions called from SQL expressions.

  5. The SQL statement executes successfully and control is passed to the calling environment.


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Employee 108 has his email name updated based on the return result of the function. This option is incorrect because the UPDATE statement inside the function updates the email name in the "employees" table, but the SELECT statement does not update any data. It only retrieves the "first_name", "last_name", and the result of the "gen_email_name" function for employee 108.

Option B) The statement fails because functions called from SQL expressions cannot perform DML. This option is correct. Functions called from SQL expressions cannot perform Data Manipulation Language (DML) operations like UPDATE, INSERT, or DELETE. In the given code, the function "gen_email_name" contains an UPDATE statement, so when it is called in the SELECT statement, it will fail.

Option C) The statement fails because the function does not contain code to end the transaction. This option is incorrect because the failure of the statement is not related to transaction control. The issue is that the function contains an UPDATE statement, which is not allowed in a function called from a SQL expression.

Option D) The SQL statement executes successfully because UPDATE and DELETE statements are ignored in stored functions called from SQL expressions. This option is incorrect. UPDATE and DELETE statements are not ignored in stored functions called from SQL expressions. They are not allowed in such functions.

Option E) The SQL statement executes successfully and control is passed to the calling environment. This option is incorrect. The SQL statement will fail due to the presence of the UPDATE statement in the function.

The correct answer is B. The statement fails because functions called from SQL expressions cannot perform DML operations like UPDATE.

Find more quizzes: