Why does this code cause an error when compiled?

Examine this code:
CREATE OR REPLACE PROCEDURE audit_emp
(p_id IN emp_empno%TYPE)
IS
v_id NUMBER;
PROCEDURE log_exec
IS
BEGIN
INSERT INTO log_table (user_id, log_delete)
VALUES (USER, SYSDATE);
END log_exec;
v_name VARCHAR2(20);
BEGIN
DELETE FROM emp
WHERE empno = p_id;
log_exec;
SELECT ename, empno
INTO v_name, v_id
FROM emp
WHERE empno = p_id;
END audit_emp;
Why does this code cause an error when compiled?

Examine this code:
CREATE OR REPLACE PROCEDURE audit_emp
(p_id IN emp_empno%TYPE)
IS
v_id NUMBER;
PROCEDURE log_exec
IS
BEGIN
INSERT INTO log_table (user_id, log_delete)
VALUES (USER, SYSDATE);
END log_exec;
v_name VARCHAR2(20);
BEGIN
DELETE FROM emp
WHERE empno = p_id;
log_exec;
SELECT ename, empno
INTO v_name, v_id
FROM emp
WHERE empno = p_id;
END audit_emp;
Why does this code cause an error when compiled?

A.
An insert statement is not allowed in a subprogram declaration.

B.
Procedure LOG_EXEC should be declared before any identifiers.

C.
Variable v_name should be declared before declaring the LOG_EXEC procedure.

D.
The LOG_EXEC procedure should be invoked as EXECUTE log_exec with the AUDIT_EMP procedure.

Explanation:
Variables must be declared before declaring any subprograms.
Incorrect Answers

A: You may have An?? Statement in a program declaration B: The opposite is true
D: You do not use the Execute when calling from a procedure.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


mike

mike

Everyone is using other peoples work. Found this incomplete term

“You may have An?? Statement in a progra” in many other documents and VCE-Files 🙂
Problem is that even WRONG answers are often copied.