Professional Documents
Culture Documents
Dokumen - Tips - 2013 2014 Oracle Academy Database Programming With PLSQL Student
Dokumen - Tips - 2013 2014 Oracle Academy Database Programming With PLSQL Student
1. To declare an INDEX BY table, we must first declare a type and then declare a collection variable of
that type. True or False?
True (*)
False
Correct
COUNT (*)
FIRST (*)
DROP
DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE
INDEX BY NUMBER;
DECLARE
TYPE t_depttab IS INDEX BY TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;
DECLARE
TYPE t_depttab IS TABLE OF departments%TYPE
INDEX BY BINARY_INTEGER;
DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;
(*)
Correct
4. What is the largest number of elements (i.e., records) that an INDEX BY table
of records can contain? Mark for Review
(1) Points
100
4096
32767
Many millions of records because a BINARY_INTEGER or PLS_INTEGER
can have a very large value (*)
None of the above
5. Which of these PL/SQL data structures could store a complete copy of the
employees table, i.e., 20 complete table rows? Mark for Review
(1) Points
An INDEX BY table
A record
Correct
Correct
Section 7
Section 1
(Answer all questions in this section)
1. Which of the following is NOT an advantage of including an exception handler in a
PL/SQL block? Mark for Review
(1) Points
Code is more readable because error-handling routines can be written in the
same block in which the error occurred
Avoids costly and time-consuming correction of mistakes
4. Only one exception at a time can be raised during one execution of a PL/SQL block.
True or False? Mark for Review
(1) Points
True (*)
False
Correct
(*)
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
END;
(*)
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
WHEN OTHERS THEN statement_3;
END;
EXCEPTION
WHEN TOO_MANY_ROWS THEN statement_1;
END;
(*)
Correct
7. Which of the following are NOT good practice guidelines for exception handling?
(Choose two.) Mark for Review
(1) Points
(Choose all correct answers)
Use an exception handler whenever there is any possibility of an error
occurring.
Handle specific named exceptions where possible, instead of relying on WHEN
OTHERS.
Test your code with different combinations of data to see what potential errors
can happen.
Allow exceptions to propagate back to the calling environment. (*)
Include a WHEN OTHERS handler as the first handler in the exception section.
(*)
8. Examine the following code. Why does this exception handler not follow good
practice guidelines? (Choose two.) Mark for Review
(1) Points
DECLARE
v_dept_name departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_dept_name FROM departments
WHERE department_id = 75;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('A select returned more than one row');
END;
(Choose all correct answers)
The exception section should include a WHEN TOO_MANY_ROWS exception
handler. (*)
You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.
The exception handler should test for the named exception NO_DATA_FOUND.
(*)
NO_DATA_FOUND
TOO_MANY_ROWS
DUP_VAL_ON_INDEX
Correct
2. Which of the following best describes a predefined Oracle Server error?
Mark for Review
(1) Points
Has a standard Oracle error number and a standard name which can be
referenced in the EXCEPTION section (*)
Is associated with an Oracle error number using PRAGMA
EXCEPTION_INIT
Has a standard Oracle error number but must be declared and named
by the PL/SQL programmer
Is not raised automatically but must be declared and raised explicitly by
the PL/SQL programmer
4. Examine the following code. At Line A, you want to raise an exception if the
employee's manager_id is null. What kind of exception is this? Mark for Review
(1) Points
DECLARE
v_mgr_id employees.manager_id%TYPE;
BEGIN
SELECT manager_id INTO v_mgr_id FROM employees
WHERE employee_id = 100;
IF v_mgr_id IS NULL THEN
-- Line A
END IF;
...
A user-defined exception (*)
A non-predefined Oracle server exception
A NO_DATA_FOUND exception
5. How would you trap Oracle Server exception ORA-01403: no data found?
Mark for Review
(1) Points
WHEN ORA-01403 THEN ...
WHEN NO_DATA_FOUND THEN ... (*)
Correct
NO_DATA_FOUND
SQL%ROWCOUNT = 0
ZERO_DIVIDE (*)
Correct
DECLARE
e_not_null EXCEPTION;
BEGIN
PRAGMA EXCEPTION_INIT(e_not_null, -1400);
INSERT INTO departments (department_id, department_name)
VALUES(null, 'Marketing');
EXCEPTION
WHEN e_not_null THEN
DBMS_OUTPUT.PUT_LINE('Cannot be null');
END;
The exception will be raised and "Cannot be null" will be displayed.
The code will not execute because the syntax of PRAGMA
EXCEPTION_INIT is wrong.
The code will not execute because PRAGMA EXCEPTION_INIT must be
coded in the DECLARE section. (*)
The code will not execute because the syntax of the INSERT statement
is wrong.
9. Examine the following code. The UPDATE statement will raise an ORA-02291
exception. Mark for Review
(1) Points
BEGIN
UPDATE employees SET department_id = 45;
EXCEPTION
WHEN OTHERS THEN
INSERT INTO error_log_table VALUES (SQLCODE);
END;
11. A PL/SQL block executes and an Oracle Server exception is raised. Which of
the following contains the text message associated with the exception? Mark for Review
(1) Points
SQL_MESSAGE_TEXT
SQL%MESSAGE
SQLCODE
SQLERRM (*)
12. Which one of the following events would implicitly raise an exception?
Mark for Review
(1) Points
A SELECT statement returns exactly one row.
1. What is a
user- Mark for Review
defined (1) Points
exception?
An exception which is not raised automatically by the Oracle server, but
must be declared and raised explicitly by the PL/SQL programmer. (*)
A predefined Oracle server exception such as NO_DATA_FOUND.
VARCHAR2
EXCEPTION (*)
NUMBER
None of the above
(*)
Message 1
Message 3
Message 4
Message 1
Message 3
Incorrect. Refer to Section 7 Lesson 3.
False (*)
None of the above. They are raised automatically by the Oracle server.
Correct
Correct
8. You want to display your own error message to the user. What is the correct
syntax to do this? Mark for Review
(1) Points
RAISE_APPLICATION_ERROR('My own message', -20001);
1. Predefined Oracle
Server exceptions Mark for Review
such as (1) Points
NO_DATA_FOUND
can be raised
automatically in
inner blocks and
handled in outer
blocks. True or
False?
True (*)
False
Correct
True
False (*)
Correct
(*)
Message 1
An unhandled exception will be propagated back to the calling
environment.
None of the above
Correct
35
Section 8
1. Which of the
following are Mark for Review
characteristics (1) Points
of anonymous
PL/SQL blocks
but not
PL/SQL
subprograms?
(Choose
three.)
(Choose all correct answers)
Can take parameters
False (*)
False (*)
Correct
DECLARE
BEGIN (*)
REPLACE
EXCEPTION
Incorrect. Refer to Section 8 Lesson 1.
A and C
B and C
A, B, and D (*)
A and B
A only
Correct
10. The following are the steps involved in creating, and later modifying and
re-creating, a PL/SQL procedure in Application Express. Which step is Mark for Review
missing? (1) Points
Correct
11. When modifying procedure code, the procedure code statement must be
re-executed to validate and store it in the database. True or False? Mark for Review
(1) Points
True (*)
False
Correct
12. A nested subprogram can be called from the main procedure or from the
calling environment. True or False? Mark for Review
(1) Points
True
False (*)
1. Which of
the Mark for Review
following (1) Points
best
describes
the
difference
between a
parameter
and an
argument?
They are both names of variables. A parameter is passed into the
procedure, while an argument is passed out of the procedure.
A parameter is the name of a variable, while an argument is the
datatype of that variable.
A parameter is a variable that accepts a value that is passed to it, while
an argument is the value that is passed. (*)
There is no difference; parameters and arguments are the same thing.
2. What is the correct syntax to create procedure MYPROC that accepts two
number parameters X and Y? Mark for Review
(1) Points
CREATE PROCEDURE myproc (x NUMBER, y NUMBER) IS ... (*)
CREATE PROCEDURE (x NUMBER, y NUMBER) myproc IS ...
CREATE PROCEDURE myproc IS (x NUMBER, y NUMBER) ...
Correct
An expression
You want to call the procedure from an anonymous block. Which of the
following calls is valid?
myproc(p_left, p_right);
myproc(v_left, v_right);
myproc(v_left, 30);
All of the above (*)
Correct
DECLARE
v_param VARCHAR2(20) := 'Smith';
BEGIN
subproc(v_param);
END;
Smith'
Correct
7. Which one of the following statements about formal and actual parameters is
true? Mark for Review
(1) Points
Formal and actual parameters must have the same name.
Formal and actual parameters must have different names.
Correct
(*)
Incorrect. Refer to Section 8 Lesson 2.
(v_num NUMBER(6,2))
1. What are
the three Mark for Review
parameter (1) Points
modes for
procedures?
IN, OUT, IN OUT (*)
Correct
2. If you don't specify a mode for a parameter, what is the default mode?
Mark for Review
(1) Points
OUT
IN (*)
COPY
DEFAULT
R(ead)
Correct
Named
A combination of positional and named (*)
CONSTANT
R(ead)
W(rite)
Correct
Which one of the following calls to the procedure will NOT work?
myproc(80, 'Smith');
add_employee('Jones');
The procedure will not compile because P_SALARY should have been
coded as DEFAULT 1000
The call will fail because P_SALARY is a required parameter
10. What will happen when the following procedure is called as format_phone
(8005551234)? Mark for Review
(1) Points
CREATE OR REPLACE PROCEDURE format_phone
(p_phone_no IN OUT VARCHAR2) IS
BEGIN
p_phone_no := SUBSTR(p_phone_no,1,3) ||
'.' || SUBSTR(p_phone_no,4,3) ||
'.' || SUBSTR(p_phone_no,7);
END format_phone;
The phone number 800.555.1234 is printed to the screen.
You want to call the procedure, passing arguments of 10 for X and 20 for
Z. Which one of the following calls is correct?
numproc(10,,20);
numproc(x=10,z=20);
numproc(10,z=>20); (*)
numproc(x=>10,20);