Final Exams em 1
Final Exams em 1
True (*)
False
Correct.
2. Identify the valid collection types:
Section 7
(Answer all questions in this section)
3. Examine the following code fragment. At Line A, you want to raise an
exception if the fetched salary value is greater than 30000. How can you
do this?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 100;
IF v_salary > 30000 THEN
-- Line A
END IF;
...
Test for WHEN VALUE_TOO_HIGH in the exception section.
Use RAISE_APPLICATION_ERROR to raise an exception explicitly. (*)
Test for WHEN OTHERS in the exception section, because WHEN
OTHERS traps all exceptions.
Define an EXCEPTION variable and associate it with an Oracle Server
error number using PRAGMA EXCEPTION_INIT.
Correct
4. An attempt to update an employee's salary to a negative value will violate
a check constraint and raise an ORA-02290 exception. Which of the
following is a correct definition of a handler for this exception?
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(-02290,e_sal_excep);
DECLARE
PRAGMA EXCEPTION_INIT(e_sal_excep,-02290);
e_sal_excep EXCEPTION;
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_excep,-02290);
(*)
DECLARE
e_sal_excep EXCEPTION;
PRAGMA_EXCEPTION_INIT(e_sal_exception,-02290);
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_excep,02290);
Correct
5. An attempt to insert a null value into a NOT NULL table column raises an
ORA-01400 exception. How can you code an exception handler to trap this
exception?
Test for WHEN ORA-1400 in the exception section.
Declare a variable e_null_excep of type EXCEPTION, associate it with
ORA-01400 using a PRAGMA directive, and test for WHEN
e_null_excep in the exception section. (*)
Declare a variable e_null_excep of type VARCHAR2, associate it with
ORA-01400 using a PRAGMA directive, and test for WHEN
e_null_excep in the exception section.
Declare a variable as follows: e_null_excep EXCEPTION := -01400;
Then test for WHEN e_null_excep in the exception section.
Correct
EXCEPTION
WHEN OTHERS THEN
INSERT INTO err_log_table (num_col, char_col)
VALUES (SQLCODE, SQLERRM);
END;
(Assume that err_log_table has been created with suitable columns and
datatypes.)
True
False (*)
Correct
8. Which of the following best describes a user-defined exception?
END;
EXCEPTION
WHEN e_constraint_violation THEN
DBMS_OUTPUT.PUT_LINE('Outer
block message');
END;
'Inner block message' will be displayed.
The code will fail because the exception is
declared in the inner block but is
referenced in the outer block. (*)
'Outer block message' will be displayed.
The code will fail because line 4 should
read: PRAGMA EXCEPTION_INIT(-2292,
e_constraint_violation);
Correct
12. What will happen when the following code is
executed?
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN BEGIN
RAISE e_excep2; END;
END;
It will fail to compile because you cannot
have a subblock inside an exception
section.
It will fail to compile because e_excep1 is
out of scope in the subblock.
It will fail to compile because you cannot
declare more than one exception in the
same block.
It will compile successfully and return an
unhandled e_excep2 to the calling
environment. (*)
Correct
13. While a PL/SQL block is executing, more than
one exception can occur at the same time. True
or False?
True
False (*)
Correct
14. Which of the following is NOT an advantage of
including an exception handler in a PL/SQL
block?
DECLARE
e_my_excep EXCEPTION;
BEGIN
BEGIN
UPDATE employees SET salary = 10000
WHERE department_id = 99;
IF SQL%ROWCOUNT = 0 THEN
RAISE e_my_excep;
END IF;
EXCEPTION
WHEN e_my_excep THEN
DBMS_OUTPUT.PUT_LINE('Message 1');
RAISE e_my_excep;
DBMS_OUTPUT.PUT_LINE('Message 2');
END;
DBMS_OUTPUT.PUT_LINE('Message 3');
EXCEPTION
WHEN e_my_excep THEN
DBMS_OUTPUT.PUT_LINE('Message 4');
END;
Message
Message
Message
Message
Message
Message
Message
Message
Message
1
3
1
2
1
3
4
1
4
(*)
Correct
18. A user-defined exception is raised by using:
FLAG exception_name;
RAISE exception-name; (*)
PRAGMA EXCEPTION_INIT
RAISE(error_number, exception_name);
Incorrect. Refer to
Section 7 Lesson 3.
B
C
A and B
B and C (*)
A and C
Incorrect. Refer to
Section 7 Lesson 3.
20. Which of the following will successfully return a
user-defined error message?
RAISE_APPLICATION_ERROR('Error
Raised',-22001);
RAISE_APPLICATION_ERROR(20257,'Error raised'); (*)
RAISE_APPLICATION_ERROR(22001,'Error Raised');
RAISE_APPLICATION_ERROR('Error
Raised',-20257);
Correct
21. Suppose
you set up
a
parameter
with an
explicit
OUT mode.
What is
true about
that
parameter?
myproc(40);
myproc(10, B => 30, 50);
myproc(C => 25);
All of the above
None of the above (*)
Correct
23. Procedure SOMEPROC has five parameters named A, B, C, D, E in that order.
The procedure was called as follows:
SOMEPROC(10,20,D=>50);
How was parameter D referenced?
Positionally
Named (*)
A combination of positionally and named
A combination of named and defaulted
Defaulted
Correct
24. Suppose you set up a parameter with an explicit IN mode. What is true about
that parameter?
True
False (*)
Correct
26. You want to create a procedure named SOMEPROC which accepts a single
parameter named SOMEPARM. The parameter can be up to 100 characters
long. Which of the following is correct syntax to do this?
(p_param IN VARCHAR2)
(p_param VARCHAR2)
(p_param VARCHAR2(50)) (*)
(p_param employees.last_name%TYPE)
(p_param IN OUT VARCHAR2)
Correct
30. Which of the following keywords MUST be included in every PL/SQL procedure
definition? (Choose three.)
PL/SQL
blocks?
(Choose
three.)
(Choose all correct answers)
Can take parameters (*)
Are stored in the database (*)
Can begin with the keyword DECLARE
Are named (*)
Are compiled every time they are executed
Correct
32. A programmer creates a PL/SQL subprogram which is compiled and stored
in the database. Two separate users then execute an application which
invokes this subprogram four times. How many times must the subprogram
be recompiled?
Two times
Four times
Zero times (*)
Eight times
One time
Correct
33. Which of the following are benefits of using PL/SQL subprograms rather
than anonymous blocks? (Choose three.)
34. The following are the steps involved in creating, and later modifying and
re-creating, a PL/SQL procedure in Application Express. In what sequence
should these steps be performed?
A.
B.
C.
D.
E.
F.
F,C,A,B,E,D
F,B,D,A,E,C (*)
E,D,F,C,A,B
F,B,D,E,A,C
F,B,C,D,E,A
Correct
35. A PL/SQL procedure named MYPROC has already been created and stored
in the database. Which of the following will successfully re-create the
procedure after some changes have been made to the code?
Section 9
(Answer all questions in this section)
36. User REYHAN creates the following procedure:
CREATE PROCEDURE proc1
AUTHID CURRENT_USER IS
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
FROM tom.employees;
END;
User BILL wants to execute this procedure. What privileges will BILL need?
EXECUTE on REYHAN.PROC1 and SELECT on TOM.EMPLOYEES (*)
EXECUTE on REYHAN.PROC1
SELECT on TOM.EMPLOYEES
BILL needs no privileges
None of the above. The procedure will fail to compile because
REYHAN does not have SELECT privilege on TOM.EMPLOYEES.
Correct
37. How do you specify that you want a procedure MYPROCA to use Invoker's
Rights?
True
False (*)
Correct
41. Which of
the
following
is a legal
location
for a
function
call in a
SQL
statement?
(Choose 3)