Semester 1 - Final PDF
Semester 1 - Final PDF
Semester 1 - Final PDF
5. You have created a procedure named MYPROC that accepts three IN parameters A,
B, and C (all numbers). Which of the following calls to MYPROC is NOT correct?
myproc(5,10,20);
myproc(a=>5,b=>10,20) (*)
myproc(a=>5,b=>10,c=>20)
myproc(5,10,c=>20)
6. Which of the following can NOT be used as the datatype of a procedure parameter?
A non-SQL datatype such as BOOLEAN
The name of another procedure (*)
A large object datatype such as CLOB
A PLSQL record defined using %ROWTYPE
7. 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 B referenced?
Positional (*)
Named
A combination of positionally and named
A combination of named and defaulted
Defaulted
8. Which parameter mode is the default?
IN (*)
OUT
NUMBER
VARIABLE
CONSTANT
9. 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
10. What are the type of parameter modes?
CHARACTER, NUMBER, DATE, BOOLEAN
CONSTANT, VARIABLE, DEFAULT
LOCAL, GLOBAL, BOTH
IN, OUT, IN OUT (*)
11. 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);
12. A user-defined exception can be raised:
A. In the declaration section
B. In the executable section
C. In the exception section
B
C
A and B
B and C (*)
A and C
13. A user-defined exception must be declared as a variable of data type EXCEPTION.
True or False?
True (*)
False
14. A user-defined exception is raised by using:
FLAG exception_name;
RAISE exception-name; (*)
PRAGMA EXCEPTION_INIT
RAISE(error_number, exception_name);
15. Examine the following code (the code of CHILD2 is not shown):
CREATE PROCEDURE child1
IS v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 9999;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END child1;
CREATE PROCEDURE parent
IS BEGIN
child1;
child2;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END parent;
Employee_id 9999 does not exist. What happens when PARENT is executed?
CHILD1 handles the exception successfully and ends. PARENT continues to execute and
invokes CHILD2. (*)
20. Which of the following are benefits of using PL/SQL subprograms rather than
anonymous blocks? (Choose three.)
Easier to write
Better data security (*)
Easier code maintenance (*)
Faster performance (*)
Do not need to declare variables
21. Which of the following are characteristics of PL/SQL stored procedures? (Choose
three)
They are named PL/SQL blocks (*)
They must return exactly one value to the calling environment.
They can have an exception section. (*)
They can be invoked from inside a SQL statement.
They can accept parameters. (*)
22. Which of the following are characteristics of PL/SQL subprograms but not of
anonymous PL/SQL blocks? (Choose three.)
Can take parameters (*)
Are stored in the database (*)
Can begin with the keyword DECLARE
Are named (*)
Are compiled every time they are executed
23. 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?
CREATE PROCEDURE myproc IS ...
CREATE OR REPLACE PROCEDURE myproc IS .... (*)
UPDATE PROCEDURE myproc IS ...
ALTER PROCEDURE myproc IS ...
None of the above, because the procedure must be dropped before it can be re-created.
24. Which of the following keywords MUST be included in every PL/SQL procedure
definition? (Choose three.)
REPLACE
BEGIN (*)
IS or AS (*)
DECLARE
END (*)
25. A programmer wants to create a PL/SQL procedure named EMP_PROC. What will
happen when the following code is executed?
CREATE OR REPLACE PROCEDURE emp_proc IS
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 999;
DBMS_OUTPUT.PUT_LINE('The salary is: ' || v_salary);
END;
The statement will raise a NO_DATA_FOUND exception because employee_id 999 does not
exist.
The statement will fail because the last line of code should be END emp_proc;
The statement will fail because you cannot declare variables such as v_salary inside a
procedure.
The procedure will be created successfully. (*)
The statement will fail because the procedure does not have any parameters.
26. 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.
27. Which kinds of exceptions are raised implicitly (i.e.,automatically)? (Choose two.)
Predefined Oracle Server errors such as NO_DATA_FOUND (*)
User-defined errors
All errors
Non-predefined Oracle Server errors such as ORA-01400 (*)
28. Which of these exceptions would need to be raised explicitly by the PL/SQL
programmer?
A SQL UPDATE statement does not update any rows. (*)
29. Examine the following code. What message or messages will be displayed when this
code is executed?
DECLARE
v_last_name employees.last_name%TYPE;
v_number NUMBER := 27;
BEGIN
v_number := v_number / 0;
SELECT last_name INTO v_last_name FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No rows were found');
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Attempt to divide by zero');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;
No rows were found
Attempt to divide by zero (*)
Attempt to divide by zero No rows were found
An error occurred
No message will be displayed
30. How can you retrieve the error code and error message of any Oracle Server
exception?
By using the functions SQLCODE and SQLERRM (*)
By using the functions SQLCODE and SQLERR
By using RAISE_APPLICATION_ERROR
By defining an EXCEPTION variable and using PRAGMA EXCEPTION_INIT
31. Which of the following are examples of predefined Oracle Server
errors? (Choose three.)
TOO_MANY_ROWS (*)
NO_DATA_FOUND (*)
OTHERS
ZERO_DIVIDE (*)
E_INSERT_EXCEP
32. In a SELECT statement, where can a function NOT be used?
In a GROUP BY or HAVING clause.
A function can be used anywhere in a SELECT statement. (*)
In a WHERE clause.
In the column list (SELECT) clause.
In an ORDER BY clause.
33. Which of the following is a difference between a procedure and a function?
A function must return a value, a procedure may or may not. (*)
FROM employees
WHERE is_leapyear(hire_date)=TRUE;
The IS_LEAPYEAR function must be in the SELECT clause, not the WHERE clause.
You cannot use DATE and BOOLEAN datatypes in the same function.
The SELECT statement returns more than one row.
IS_LEAPYEAR is a reserved word in the SQL language.
The function returns a Boolean, and therefore cannot be used within a SELECT statement. (*)
40. Where can a function be used in a query?
Nowhere in a query.
Anywhere in a query. (*)
Only in the SELECT clause
Only in the WHERE clause
In the SELECT or WHERE clauses, but not in the ORDER BY clause.
41. What will happen when the following code is executed?
BEGIN -- outer block
DECLARE -- inner block
CURSOR emp_curs IS SELECT * FROM employees;
v_emp_rec emp_curs%ROWTYPE;
BEGIN
OPEN emp_curs;
LOOP
FETCH emp_curs INTO v_emp_rec;
DBMS_OUTPUT.PUT_LINE(v_emp_rec.salary);
END LOOP;
END;
CLOSE emp_curs;
END;
The code will fail because you cannot declare a cursor in an inner block.
The code will fail because the cursor is declared in the inner block but is referenced in the
outer block. (*)
The code will execute successfully and display all the employees' salaries.
The code will execute forever because there is no statement to EXIT from the loop.
42. What will be displayed when the following code is executed?
<<outer>>
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 10;
DECLARE
v_myvar NUMBER := 200;
BEGIN
outer.v_myvar := 20;
v_myvar := v_myvar / 0; -- this raises a ZERO_DIVIDE error
outer.v_myvar := 30;
END;
v_myvar := 40;
EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE(v_myvar);
END;
10
20 (*)
30
40
200
43. Examine the following code. What is the scope and visibility of the outer block's
v_last_name?
DECLARE
v_last_name VARCHAR2(20);
BEGIN
DECLARE
v_last_name VARCHAR2(20);
BEGIN
...
END:
...
END;
It is in scope and visible in both blocks.
It is in scope and visible in the outer block only.
It is in scope in both blocks, but visible only in the outer block.(*)
It is visible in both blocks, but in scope only in the outer block.
44. Using two nested blocks, a TOO_MANY_ROWS exception is raised within the inner
block. Which of the following exception handlers will successfully handle the exception?
WHEN TOO_MANY_ROWS in the inner block
WHEN TOO_MANY_ROWS in either block
WHEN OTHERS in either block
WHEN OTHERS in the inner block
All of the above (*)
45. There are no employees in department 75. What will be displayed when this code is
executed?
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('A');
BEGIN
SELECT last_name INTO v_last_name
49. Which of the following are good practice guidelines for exception handling? (Choose
three.)
Test your code with different combinations of data to see what potential errors can happen.
(*)
Use an exception handler whenever there is any possibility of an error occurring. (*)
Include a WHEN OTHERS handler as the first handler in the exception section.
Allow exceptions to propagate back to the calling environment.
Handle specific named exceptions where possible, instead of relying on WHEN OTHERS. (*)
50. Which of these exceptions can be handled by an EXCEPTION section in a PL/SQL
block?
A SELECT statement returns no rows
A SELECT statement returns more than one row
Any other kind of exception that can occur within the block
All of the above (*)
None of the above