God Save Us
God Save Us
1. Examine the following code. Why does the exception handler not
follow good practice guidelines?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END; Mark for Review
(1) Points
2. While a PL/SQL block is executing, more than one exception can occur
at the same time. True or False? Mark for Review
(1) Points
True
False (*)
1
An error occurs during execution which disrupts the
normal operation of the program. (*)
5. You try to create a function named MYFUNC. The function does not
compile correctly because there are errors in your code. Which Dictionary view can you query
to see the errors? Mark for Review
(1) Points
USER_SOURCE
USER_ERRORS (*)
USER_OBJECTS
USER_DEPENDENCIES
USER_COMPILES
2
A subprogram that must return exactly one value. (*)
Correct
Which one of the following blocks will NOT work correctly? Mark for Review
(1) Points
DECLARE
x NUMBER;
BEGIN
x:= add_em(b=4);
END;
(*)
DECLARE
x NUMBER;
BEGIN
x:= add_em(4);
END;
DECLARE
x NUMBER;
BEGIN
x:= add_em(4,5);
END;
3
DECLARE
x NUMBER;
BEGIN
x:= add_em;
END;
Correct
DECLARE
v_var1 NUMBER(6,2);
BEGIN
-- Line A
END;
What could be coded at Liine A? Mark for Review
(1) Points
myfunc('Crocodile') := v_var1;
myfunc(v_var1) := 'Crocodile';
myfunc(v_var1, 'Crocodile');
myfunc('Crocodile', v_var1);
4
You must declare the type of the RETURN before the IS.
(*)
TED's privileges
PUBLIC's privileges
SYSTEM's privileges
ORACLE's privileges
5
Incorrect. Refer to Section 8.
12. How do you specify that you want a procedure MYPROCA to use
"Definer's Rights"? Mark for Review
(1) Points
13. The following exception handler will successfully insert the Oracle
error number and error message into a log table whenever an Oracle Server error occurs. True
or False?
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.) Mark
for Review
(1) Points
True
False (*)
6
14. Which of these exceptions would need to be raised explicitly by the
PL/SQL programmer? Mark for Review
(1) Points
OTHERS
User-defined errors
All errors
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(-02290,e_sal_excep);
7
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);
17. Which of the following best describes a predefined Oracle Server error?
Mark for Review
(1) Points
DECLARE
v_last_name employees.last_name%TYPE;
8
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; Mark for Review
(1) Points
An error occurred
9
20. A stored PL/SQL procedure can be invoked from which of the
following?
A only
A and B
A and C
A, B and C (*)
B and C
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
10
True (*)
False
Correct
REPLACE
BEGIN (*)
IS or AS (*)
DECLARE
END (*)
11
25. In which DML statements can user-defined functions be used? Mark
for Review
(1) Points
INSERT only.
UPDATE only
DELETE only
12
They allow you to use functions which return a
BOOLEAN.
Correct
13
p_param is a formal parameter and v_param is an actual
parameter (*)
30. A procedure will execute faster if it has at least one parameter. Mark
for Review
(1) Points
True
False (*)
14
32. You have created the following procedure:
CREATE OR REPLACE PROCEDURE double_it
(p_param IN OUT NUMBER)
IS
BEGIN
p_param := p_param * 2;
END;
Which of the following anonymous blocks invokes this procedure successfully? Mark for
Review
(1) Points
BEGIN
EXECUTE double_it(20);
END;
BEGIN
SELECT double_it(20)
FROM DUAL;
END;
DECLARE
v_result NUMBER(6);
BEGIN
v_result := double_it(20);
END;
DECLARE
v_result NUMBER(6) := 20;
BEGIN
double_it(v_result);
END; (*)
BEGIN
double_it(20);
END;
33. 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? Mark for Review
(1) Points
myproc(5,10,20);
myproc(a=>5,b=>10,20) (*)
15
myproc(a=>5,b=>10,c=>20)
myproc(5,10,c=>20)
34. Department-id 99 does not exist. What will be displayed when the
following code is executed?
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_deptname
FROM departments WHERE department_id = 99;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20201,'Department does not exist');
END; Mark for Review
(1) Points
A and B
B and C (*)
16
A and C
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; Mark for Review
(1) Points
Message 1
Message 3
Message 1
Message 2
Message 1
Message 3
Message 4
Message 1
Message 4
(*)
17
37. Which of the following will successfully return a user-defined error
message? Mark for Review
(1) Points
RAISE_APPLICATION_ERROR('Error Raised',-
22001);
RAISE_APPLICATION_ERROR(-20257,'Error raised');
(*)
RAISE_APPLICATION_ERROR(-22001,'Error
Raised');
RAISE_APPLICATION_ERROR('Error Raised',-
20257);
SOMEPROC(10,20,D=>50);
Positional (*)
Named
Defaulted
Correct
39. What are the type of parameter modes? Mark for Review
(1) Points
18
LOCAL, GLOBAL, BOTH
IN (*)
OUT
NUMBER
VARIABLE
CONSTANT
Correct
41. The following procedure has been created:
myproc(40);
42. You want to remove the procedure NO_NEED from your schema. You
execute:
19
DROP PROCEDURE no_need;
Which Data Dictionary views are updated automatically? Mark for Review
(1) Points
USER_PROCEDURES
USER_OBJECTS
USER_SOURCE
20
44. You want to see the names, modes and data types of the formal
parameters of function MY_FUNC in your schema. How can you do this? (Choose two)
Mark for Review
(1) Points
Query USER_PARAMETERS
Query USER_FUNCTIONS
45. The following code does not violate any constraints and will not raise
an ORA-02292 error. What will happen when the code is executed?
BEGIN
DECLARE
e_constraint_violation EXCEPTION;
PRAGMA EXCEPTION_INIT(e_constraint_violation, -2292);
BEGIN
DBMS_OUTPUT.PUT_LINE('Inner block message');
END;
EXCEPTION
WHEN e_constraint_violation THEN
DBMS_OUTPUT.PUT_LINE('Outer block message');
END; Mark for Review
(1) Points
21
m Semester 1
46. 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
FROM employees WHERE department_id = 75;
DBMS_OUTPUT.PUT_LINE('B');
END;
DBMS_OUTPUT.PUT_LINE('C');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('D');
END; Mark for Review
(1) Points
A
C
D
A
D
(*)
A
B
D
47. Examine the following code which shows three levels of nested block.
What is the scope of the variable v_middle_var?
22
v_outer_var NUMBER;
BEGIN
DECLARE -- middle block
v_middle_var NUMBER;
BEGIN
DECLARE -- inner block
v_inner_var NUMBER;
BEGIN
...
END;
END;
END; Mark for Review
(1) Points
<<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; Mark for Review
(1) Points
10
23
20 (*)
30
40
200
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN BEGIN
RAISE e_excep2; END;
END; Mark for Review
(1) Points
24
It will fail to compile because you cannot declare more
than one exception in the same block.
25
2
1. User-defined exceptions must be declared explicitly by the programmer, but then are
raised automatically by the Oracle Server. True or False? Mark for Review
(1) Points
True
False (*)
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_deptname
FROM departments WHERE department_id = 99;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20201,'Department does not exist');
END; Mark for Review
(1) Points
26
A and B
B and C (*)
A and C
RAISE_APPLICATION_ERROR('Error Raised',-
22001);
RAISE_APPLICATION_ERROR(-20257,'Error raised');
(*)
RAISE_APPLICATION_ERROR(-22001,'Error
Raised');
RAISE_APPLICATION_ERROR('Error Raised',-
20257);
27
The function returns a Boolean, and therefore cannot be
used within a SELECT statement. (*)
INSERT only.
UPDATE only
DELETE only
Correct
28
A SELECT statement returns more than one row
9. Examine the following code. Why does the exception handler not
follow good practice guidelines?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END; Mark for Review
(1) Points
EXCEPTION
WHEN NO_DATA_FOUND OR TOO_MANY_ROWS
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
29
END; Mark for Review
(1) Points
True (*)
False
Correct
11. While a PL/SQL block is executing, more than one exception can occur at the same
time. True or False? Mark for Review
(1) Points
True
False (*)
12. The following code shows the dependencies between three procedures:
30
13. Which Data Dictionary view can be used to display the detailed code of
a procedure in your schema? Mark for Review
(1) Points
USER_PROCEDURES
USER_OBJECTS
USER_SOURCE (*)
USER_SUBPROGRAMS
14. You want to see the names, modes and data types of the formal
parameters of function MY_FUNC in your schema. How can you do this? (Choose two)
Mark for Review
(1) Points
Query USER_PARAMETERS
Query USER_FUNCTIONS
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(-02290,e_sal_excep);
31
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);
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;
... Mark for Review
(1) Points
32
Incorrect. Refer to Section 6.
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; Mark for Review
(1) Points
An error occurred
33
Any error which has an Oracle error number of the form
ORA-nnnnn
TOO_MANY_ROWS (*)
NO_DATA_FOUND (*)
OTHERS
ZERO_DIVIDE (*)
E_INSERT_EXCEP
20. 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?
Mark for Review
(1) Points
34
A subprogram that must return exactly one value. (*)
Correct
Which one of the following blocks will NOT work correctly? Mark for Review
(1) Points
DECLARE
x NUMBER;
BEGIN
x:= add_em(b=4);
END;
(*)
DECLARE
x NUMBER;
BEGIN
x:= add_em(4);
END;
DECLARE
x NUMBER;
BEGIN
x:= add_em(4,5);
END;
35
DECLARE
x NUMBER;
BEGIN
x:= add_em;
END;
Correct
In a WHERE clause.
In an ORDER BY clause.
36
A procedure can include an EXCEPTION section, while
a function cannot.
You must declare the type of the RETURN before the IS.
(*)
37
27. The following procedure has been created:
defproc;
IN (*)
OUT
NUMBER
VARIABLE
CONSTANT
Correct
29. What are the type of parameter modes? Mark for Review
(1) Points
38
LOCAL, GLOBAL, BOTH
30. Suppose you set up a parameter with an explicit IN mode. What is true
about that parameter? Mark for Review
(1) Points
(p_param IN VARCHAR2)
(p_param VARCHAR2)
(p_param employees.last_name%TYPE)
39
DECLARE
v_param NUMBER := 20;
BEGIN
smallproc(v_param);
END;
Which of the following statements is true? Mark for Review
(1) Points
40
34. 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? Mark for Review
(1) Points
myproc(5,10,20);
myproc(a=>5,b=>10,20) (*)
myproc(a=>5,b=>10,c=>20)
myproc(5,10,c=>20)
35. A procedure will execute faster if it has at least one parameter. Mark
for Review
(1) Points
True
False (*)
37. 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');
41
BEGIN
SELECT last_name INTO v_last_name
FROM employees WHERE department_id = 75;
DBMS_OUTPUT.PUT_LINE('B');
END;
DBMS_OUTPUT.PUT_LINE('C');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('D');
END; Mark for Review
(1) Points
A
C
D
A
D
(*)
A
B
D
DECLARE
v_myvar1 NUMBER;
BEGIN
DECLARE
v_myvar2 NUMBER;
BEGIN
v_myvar1 := 100;
END;
v_myvar2 := 100; v END; Mark for Review
(1) Points
42
True
False (*)
<<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; Mark for Review
(1) Points
10
20 (*)
30
40
200
43
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; Mark for Review
(1) Points
You must label the outer block when two variables with
the same name are declared, one in each block.
You must label the outer block when two variables with
the same name are declared and you need to reference the outer block's variable within the
inner block. (*)
42. Examine the following code which shows three levels of nested block.
What is the scope of the variable v_middle_var?
44
v_outer_var NUMBER;
BEGIN
DECLARE -- middle block
v_middle_var NUMBER;
BEGIN
DECLARE -- inner block
v_inner_var NUMBER;
BEGIN
...
END;
END;
END; Mark for Review
(1) Points
EXECUTE on REYHAN.PROC1
SELECT on TOM.EMPLOYEES
Correct
45
44. User BOB creates procedure MYPROC using the default Definer's
Rights. BOB then executes:
GRANT EXECUTE ON bob.myproc TO ted;
When TED invokes BOB.MYPROC, whose privileges are checked? Mark for Review
(1) Points
TED's privileges
PUBLIC's privileges
SYSTEM's privileges
ORACLE's privileges
45. 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? Mark for Review
(1) Points
A only
A and B
A and C
A, B and C (*)
46
B and C
Easier to write
47
Do not need to declare variables
True (*)
False
Correct
48
3
Final Exam Semester 1
User-defined errors
All errors
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; Mark for Review
(1) Points
An error occurred
49
No message will be displayed
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.) Mark
for Review
(1) Points
True
False (*)
4. How can you retrieve the error code and error message of any Oracle
Server exception? Mark for Review
(1) Points
By using RAISE_APPLICATION_ERROR
Correct
50
OTHERS
DECLARE
v_var1 NUMBER(6,2);
BEGIN
-- Line A
END;
What could be coded at Liine A? Mark for Review
(1) Points
myfunc('Crocodile') := v_var1;
myfunc(v_var1) := 'Crocodile';
myfunc(v_var1, 'Crocodile');
myfunc('Crocodile', v_var1);
12. You have created a function named NEWFUNC. You now change
some of the function code, and try to recreate the function by executing:
51
The function is automatically dropped and then
recreated. (*)
13. Department-id 99 does not exist. What will be displayed when the
following code is executed?
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_deptname
FROM departments WHERE department_id = 99;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20201,'Department does not exist');
END; Mark for Review
(1) Points
DECLARE
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
FROM employees WHERE department_id = 99;
IF v_count = 0 THEN
52
RAISE NO_DATA_FOUND;
DBMS_OUTPUT.PUT_LINE('No employees found');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Department 99 is empty');
END; Mark for Review
(1) Points
No employees found
FLAG exception_name;
PRAGMA EXCEPTION_INIT
RAISE(error_number, exception_name);
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');
53
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; Mark for Review
(1) Points
Message 1
Message 3
Message 1
Message 2
Message 1
Message 3
Message 4
Message 1
Message 4
(*)
17. You have created procedure MYPROC with a single parameter PARM1
NUMBER. Now you want to add a second parameter to the procedure. Which of the
following will change the procedure successfully? Mark for Review
(1) Points
54
BEGIN ...
Correct
55
An actual parameter is declared in the calling
environment, not in the called procedure
20. Which of the following can NOT be used as the datatype of a procedure
parameter? Mark for Review
(1) Points
(p_param IN VARCHAR2)
(p_param VARCHAR2)
(p_param employees.last_name%TYPE)
56
CREATE OR REPLACE PROCEDURE double_it
(p_param IN OUT NUMBER)
IS
BEGIN
p_param := p_param * 2;
END;
Which of the following anonymous blocks invokes this procedure successfully? Mark for
Review
(1) Points
BEGIN
EXECUTE double_it(20);
END;
BEGIN
SELECT double_it(20)
FROM DUAL;
END;
DECLARE
v_result NUMBER(6);
BEGIN
v_result := double_it(20);
END;
DECLARE
v_result NUMBER(6) := 20;
BEGIN
double_it(v_result);
END; (*)
BEGIN
double_it(20);
END;
EXECUTE on REYHAN.PROC1
57
SELECT on TOM.EMPLOYEES
Correct
24. How do you specify that you want a procedure MYPROCA to use
Invoker's Rights? Mark for Review
(1) Points
(*)
Correct
58
The programmer makes a spelling mistake while writiing
the PL/SQL code.
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
END;
(*)
EXCEPTION
WHEN OTHERS THEN statement_2;
WHEN NO_DATA_FOUND THEN statement_1;
END;
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
WHEN OTHERS THEN statement_3;
END;
EXCEPTION
59
WHEN OTHERS THEN statement_1;
END;
(*)
EXCEPTION
WHEN NO_DATA_FOUND OR TOO_MANY_ROWS
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END; Mark for Review
(1) Points
True (*)
False
Correct
29. Examine the following code which shows three levels of nested block.
What is the scope of the variable v_middle_var?
60
Middle and inner blocks only (*)
30. The following code does not violate any constraints and will not raise
an ORA-02292 error. What will happen when the code is executed?
BEGIN
DECLARE
e_constraint_violation EXCEPTION;
PRAGMA EXCEPTION_INIT(e_constraint_violation, -2292);
BEGIN
DBMS_OUTPUT.PUT_LINE('Inner block message');
END;
EXCEPTION
WHEN e_constraint_violation THEN
DBMS_OUTPUT.PUT_LINE('Outer block message');
END; Mark for Review
(1) Points
DECLARE
v_myvar1 NUMBER;
BEGIN
DECLARE
v_myvar2 NUMBER;
BEGIN
v_myvar1 := 100;
END;
v_myvar2 := 100; v END; Mark for Review
61
(1) Points
True
False (*)
32. 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
FROM employees WHERE department_id = 75;
DBMS_OUTPUT.PUT_LINE('B');
END;
DBMS_OUTPUT.PUT_LINE('C');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('D');
END; Mark for Review
(1) Points
A
C
D
A
D
(*)
A
B
D
62
Incorrect. Refer to Section 6.
DECLARE
e_outer_excep EXCEPTION;
BEGIN
DECLARE
e_inner_excep EXCEPTION;
BEGIN
RAISE e_outer_excep;
END;
EXCEPTION
WHEN e_outer_excep THEN
DBMS_OUTPUT.PUT_LINE('Outer raised');
WHEN e_inner_excep THEN
DBMS_OUTPUT.PUT_LINE('Inner raised');
END; Mark for Review
(1) Points
Correct
34. Which of the following will display the value 'Smith'? Mark for
Review
(1) Points
<<outer>>
DECLARE
v_name VARCHAR2(10) := 'Smith';
BEGIN
DECLARE
v_name VARCHAR2(10) := 'Jones';
BEGIN
DBMS_OUTPUT.PUT_LINE(v_name);
63
END;
END;
<<outer>>
DECLARE
v_name VARCHAR2(10) := 'Smith';
BEGIN
DECLARE
v_name VARCHAR2(10) := 'Jones';
BEGIN
DBMS_OUTPUT.PUT_LINE(<<outer>>.v_name);
END;
END;
<<outer>>
DECLARE
v_name VARCHAR2(10) := 'Smith';
BEGIN
DECLARE
v_name VARCHAR2(10) := 'Jones';
BEGIN
DBMS_OUTPUT.PUT_LINE(outer.v_name);
END;
END;
(*)
<<outer>>
DECLARE
v_name VARCHAR2(10) := 'Smith';
BEGIN
<<inner>>
DECLARE
v_name VARCHAR2(10) := 'Jones';
BEGIN
DBMS_OUTPUT.PUT_LINE(v_name);
END;
END;
64
True (*)
False
Correct
36. A programmer wants to create a PL/SQL procedure named EMP_PROC. What will
happen when the following code is executed?
65
They can be invoked from inside a SQL statement.
A only
A and B
A and C
A, B and C (*)
B and C
Twice
Four times
None (*)
Eight times
Once
66
40. Which of the following are characteristics of PL/SQL subprograms but
not of anonymous PL/SQL blocks? (Choose three.) Mark for Review
(1) Points
42. Which of the following are NOT allowed in a function which is used
inside a SQL statement which updates the EMPLOYEES table? (Choose two). Mark for
Review
(1) Points
67
SELECT .... FROM departments ....;
COMMIT; (*)
A RETURN statement.
IN (*)
OUT
NUMBER
VARIABLE
CONSTANT
Correct
68
45. What are the type of parameter modes? Mark for Review
(1) Points
myproc(40);
69
defproc(30, 60 => C);
defproc;
48. You want to see the names, modes and data types of the formal
parameters of function MY_FUNC in your schema. How can you do this? (Choose two)
Mark for Review
(1) Points
Query USER_PARAMETERS
Query USER_FUNCTIONS
70
CHILD1 ends abruptly. PARENT handles the exception
and then ends. CHILD2 does not execute. (*)
50. Which Data Dictionary view can be used to display the detailed code of
a procedure in your schema? Mark for Review
(1) Points
USER_PROCEDURES
USER_OBJECTS
USER_SOURCE (*)
USER_SUBPROGRAMS
SELECT (*)
DBMS_LOB.PUT
DBMS_LOB.GETLENGTH
DBMS_LOB.READ (*)
71
2. You need to store very large amounts of text data in a table column
inside the database. Which datatype should you use for this column? Mark for Review
(1) Points
CLOB (*)
BLOB
LONG
VARCHAR2(4000)
Correct
(*)
72
A BLOB can contain text data while a BFILE cannot.
For applicant_id 100, we want to modify the value of the RESUME column value from "I
worked for Oracle" to "I worked for Oracle for five years".
Which of the following will do this successfully? (Choose two.) Mark for Review
(1) Points
UPDATE job_applicants
SET SUBSTR(resume, 21,14) = 'for five years'
WHERE candidate_id = 100;
UPDATE job_applicants
SET resume = 'I worked for Oracle for five years'
WHERE candidate_id = 100;
(*)
DECLARE
v_locator CLOB;
BEGIN
v_locator := 'I worked for Oracle for five years';
UPDATE job_applicants
SET resume = DBMS_LOB.WRITE(v_locator)
WHERE candidate_id = 100;
END;
73
DECLARE
v_lobloc CLOB;
BEGIN
SELECT resume INTO v_lobloc FROM job_applicants
WHERE applicant_id = 100;
DBMS_LOB.WRITE(v_lobloc,14,21,'for five years');
END;
(*)
How would the DBA allow all database users to query the BFILEs in this directory? Mark
for Review
(1) Points
74
Incorrect. Refer to Section 11.
DECLARE
v_locator BFILE;
BEGIN
SELECT resume INTO v_locator FROM bigemp
WHERE employee_id = 100;
-- Point A
DBMS_LOB.FILEOPEN(v_locator);
DBMS_LOB.READ(v_locator, ....); ....
DBMS_LOB.FILECLOSE(v_locator);
END IF;
END; Mark for Review
(1) Points
IF DBMS_LOB.FILEEXISTS(v_locator) THEN
IF DBMS_LOB.FILEEXISTS THEN
IF BFILEEXISTS(v_locator) THEN
DECLARE
v_myrec IS RECORD mypack.mytype;
BEGIN ...
DECLARE
v_myrec mypack.mytype;
75
BEGIN ...
(*)
DECLARE
v_myrec mytype;
BEGIN ...
DECLARE
v_myrec IS RECORD (mypack.mytype);
BEGIN ...
10. Which of the following will declare a composite PL/SQL data type
named COMPO_TYPE, containing two fields named FIELD1 and FIELD2? Mark for
Review
(1) Points
DECLARE
compo_type
(field1 NUMBER,
field2 VARCHAR2(30));
DECLARE
TYPE compo_type IS
(field1 NUMBER,
field2 VARCHAR2(30));
DECLARE
TYPE compo_type IS RECORD
(field1 NUMBER,
field2 VARCHAR2(30));
(*)
DECLARE
compo_type IS RECORD
(field1 NUMBER,
field2 VARCHAR2(30));
76
11. Which of the following PL/SQL data structures can store a collection? (Choose two.)
Mark for Review
(1) Points
A record
%ROWTYPE
A BLOB
True
False (*)
DECLARE
TYPE t_dnames IS TABLE OF
departments.department_name%TYPE
INDEX BY INTEGER;
dept_names_tab t_dnames;
DECLARE
TYPE t_dnames IS TABLE OF
departments.department_name%TYPE
INDEX BY BINARY_INTEGER;
dept_names_tab t_dnames;
77
(*)
DECLARE
TYPE t_dnames IS TABLE OF
departments.department_name%TYPE
INDEX BY PLS_INTEGER;
dept_names_tab t_dnames%TYPE;
DECLARE
TYPE t_dnames IS TABLE OF
department_name
INDEX BY BINARY_INTEGER;
dept_names_tab t_dnames;
14. Which of the following will display the number of invalid package
bodies in your schema? Mark for Review
(1) Points
(*)
Correct
78
15. A SELECT from the DEPTREE table displays table LOCATIONS at
nested level 0 and procedure LOCPROC at nested level 2. This shows that LOCPROC is
directly dependent on LOCATIONS. True or False? Mark for Review
(1) Points
True
False (*)
Which of the following changes to the LOCATIONS table will allow the procedure to be
recompiled successfully without editing its code? (Choose two.) Mark for Review
(1) Points
BEGIN
utldtree('DEPARTMENTS');
END;
BEGIN
deptree_fill('TABLE','BOB','DEPARTMENTS');
END;
(*)
79
BEGIN
deptree_fill('TABLE','DEPARTMENTS');
END;
BEGIN
ideptree('TABLE','BOB','DEPARTMENTS');
END;
18. When a table is dropped, all PL/SQL subprograms that reference the
table are automatically dropped. True or False? Mark for Review
(1) Points
True
False (*)
19. Which of the following is NOT created when the utldtree.sql script is
run? Mark for Review
(1) Points
20. Which of the following will display dependency information which has
been generated by executing the DEPTREE_FILL procedure? (Choose two.) Mark for
Review
(1) Points
80
The USER_DEPENDENCIES view
2
1. Which of the following PL/SQL data structures can store a collection? (Choose two.)
Mark for Review
(1) Points
A record
%ROWTYPE
81
A BLOB
DECLARE
TYPE t_emp_sals IS TABLE OF employees.salary%TYPE
INDEX BY BINARY_INTEGER;
emp_sals_tab t_emp_sals;
BEGIN
FOR v_emprec IN (SELECT employee_id, salary FROM employees)
LOOP
-- Line A
END LOOP;
END;
emp_sals_tab(employee_id) := v_emprec.salary;
t_emp_sals(v_emprec.employee_id) := v_emprec.salary;
emp_sals_tab(v_emprec.employee_id) :=
v_emprec.salary; (*)
emp_sals_tab(i) := v_emprec.salary;
An INDEX BY table
A record
A CLOB
82
An explicit cursor
5. BLOB, JPEG, BFILE and MP3 are all LOB column datatypes. True or
False? Mark for Review
(1) Points
True
False (*)
CLOB (*)
BLOB
LONG
VARCHAR2(4000)
83
Correct
True (*)
False
Correct
SELECT (*)
DBMS_LOB.PUT
DBMS_LOB.GETLENGTH
DBMS_LOB.READ (*)
9. BFILEs are stored outside the database and can be queried and updated
by using procedures in DBMS_LOB. True or False? Mark for Review
(1) Points
True
False (*)
10. Which of the following statements about BFILEs are NOT true?
(Choose two.) Mark for Review
(1) Points
84
(Choose all correct answers)
USER_DIRECTORIES
USER_BFILES
ALL_DIRECTORIES (*)
USER_EXTERNAL_FILES
ALL_BFILES
12. Package ED_PACK has declared a record type named ED_TYPE in the
package specification. Which of the following anonymous blocks successfully declares a
variable whose datatype is ED_TYPE? Mark for Review
(1) Points
DECLARE
v_ed_rec IS RECORD ed_pack.ed_type;
BEGIN ...
DECLARE
v_ed_rec ed_pack.ed_type;
BEGIN ...
85
(*)
DECLARE
v_ed_rec ed_pack.ed_type%ROWTYPE;
BEGIN...
DECLARE
v_ed_rec ed_pack.ed_type%TYPE;
BEGIN ...
DECLARE
v_myrec IS RECORD mypack.mytype;
BEGIN ...
DECLARE
v_myrec mypack.mytype;
BEGIN ...
(*)
DECLARE
v_myrec mytype;
BEGIN ...
DECLARE
v_myrec IS RECORD (mypack.mytype);
BEGIN ...
86
14. A single procedure can be both a referenced object and a dependent
object. True or False? Mark for Review
(1) Points
True (*)
False
Correct
v_last_name VARCHAR2(25);
True
False (*)
87
Incorrect. Refer to Section 12.
17. Which of the following techniques will make it more likely that an
invalidated PL/SQL subprogram will recompile successfully? (Choose two.) Mark for
Review
(1) Points
BEGIN
utldtree('DEPARTMENTS');
END;
BEGIN
deptree_fill('TABLE','BOB','DEPARTMENTS');
END;
(*)
BEGIN
deptree_fill('TABLE','DEPARTMENTS');
END;
BEGIN
ideptree('TABLE','BOB','DEPARTMENTS');
END;
88
Incorrect. Refer to Section 12.
19. When a table is dropped, all PL/SQL subprograms that reference the
table are automatically dropped. True or False? Mark for Review
(1) Points
True
False (*)
20. Which of the following is NOT created when the utldtree.sql script is
run? Mark for Review
(1) Points
3
1. An INDEX BY table of records can store a maximum of 255 records. True or False?
Mark for Review
(1) Points
True
False (*)
89
(1) Points
An INDEX BY table
A record
A CLOB
An explicit cursor
DECLARE
CURSOR emp_curs IS
SELECT employee_id, first_name, last_name FROM employees;
TYPE t_mytype IS TABLE OF -- Point A
INDEX BY BINARY_INTEGER;
v_mytab t_mytype;
employees%ROWTYPE
employees.salary%TYPE
emp_curs%ROWTYPE
DECLARE
compo_type
(field1 NUMBER,
90
field2 VARCHAR2(30));
DECLARE
TYPE compo_type IS
(field1 NUMBER,
field2 VARCHAR2(30));
DECLARE
TYPE compo_type IS RECORD
(field1 NUMBER,
field2 VARCHAR2(30));
(*)
DECLARE
compo_type IS RECORD
(field1 NUMBER,
field2 VARCHAR2(30));
DECLARE
v_ed_rec IS RECORD ed_pack.ed_type;
BEGIN ...
DECLARE
v_ed_rec ed_pack.ed_type;
BEGIN ...
(*)
DECLARE
v_ed_rec ed_pack.ed_type%ROWTYPE;
BEGIN...
DECLARE
v_ed_rec ed_pack.ed_type%TYPE;
BEGIN ...
91
None of the above. Variables of datatype ED_TYPE can
be declared only within ED_PACK, not in separate subprograms or anonymous blocks.
USER_DIRECTORIES
USER_BFILES
ALL_DIRECTORIES (*)
USER_EXTERNAL_FILES
ALL_BFILES
8. BFILEs are stored outside the database and can be queried and updated
by using procedures in DBMS_LOB. True or False? Mark for Review
(1) Points
True
92
False (*)
SELECT (*)
DBMS_LOB.PUT
DBMS_LOB.GETLENGTH
DBMS_LOB.READ (*)
10. BLOB, JPEG, BFILE and MP3 are all LOB column datatypes. True or
False? Mark for Review
(1) Points
True
False (*)
93
A LONG RAW column can store up to 2GB of data.
(*)
True (*)
False
Correct
94
Which of the following changes to the LOCATIONS table will allow the procedure to be
recompiled successfully without editing its code? (Choose two.) Mark for Review
(1) Points
15. Which of the following will display dependency information which has
been generated by executing the DEPTREE_FILL procedure? (Choose two.) Mark for
Review
(1) Points
95
SELECTing a list of column-names instead of using
SELECT *
17. Which of the following will display the number of invalid package
bodies in your schema? Mark for Review
(1) Points
(*)
Correct
18. Which of the following is NOT created when the utldtree.sql script is
run? Mark for Review
(1) Points
96
Incorrect. Refer to Section 12.
When will the ORACLE server try to recompile FETCH_EMP automatically? Mark for
Review
(1) Points
BEGIN
utldtree('DEPARTMENTS');
END;
BEGIN
deptree_fill('TABLE','BOB','DEPARTMENTS');
END;
(*)
BEGIN
deptree_fill('TABLE','DEPARTMENTS');
END;
BEGIN
ideptree('TABLE','BOB','DEPARTMENTS');
END;
97
Incorrect. Refer to Section 12.
Mid Term Exam Semester 1 - Part 1
1. 1. Null
2. False
3. True
4. 0
Which of the above can be assigned to a Boolean variable?
Mark for Review
(1) Points
2 and 3
2, 3 and 4
1, 2 and 3 (*)
1, 2, 3 and 4
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
True (*)
False
98
4. Variables can be used in the following ways in a PL/SQL block.
(Choose two.) Mark for Review
(1) Points
To comment code.
Correct.
Correct.
Correct
99
True (*)
False
Correct
True (*)
False
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
10. ______ are meant to store large amounts of data. Mark for
Review
(1) Points
Variables
LOBs (*)
100
11. Which statement most closely describes "data type"? Mark for
Review
(1) Points
Correct
True
False (*)
A NULL is displayed.
101
Incorrect. Refer to Section 3.
14. Which is the correct way to erase one row from a table? Mark
for
Review
(1) Points
REMOVE employee_id=100
FROM employees;
TRUNCATE employees
WHERE employee_id=100;
15. Delimiters are _____ that have special meaning to the Oracle
database. Mark for Review
(1) Points
identifiers
variables
symbols (*)
Correct
16. Which of the following are PL/SQL lexical units? (Choose two.)
Mark
for Review
(1) Points
Identifiers (*)
102
Table Columns
Anonymous Blocks
SQL Workshop
17. Which statements about lexical units are true? (Choose two.)
Mark
for Review
(1) Points
They are optional but can make a PL/SQL block execute faster
Correct
103
outer_block.v_myvar := 22; (*)
v_myvar := 22;
<<outer_block>>.v_myvar := 22;
v_myvar(outer_block) := 22;
12
20
VarB
Correct
104
var_a := var_a * 2;
var_b := '28 December 2006'; -- Line A
var_a := var_a * 2;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_a);
END;
Mark for Review
(1) Points
12 (*)
24
Susan
Chang (*)
ChangChang
SusanChang
105
Incorrect. Refer to Section 2.
True (*)
False
DECLARE (*)
BEGIN
EXCEPTION (*)
END;
Correct
24. Every PL/SQL anonymous block must start with the keyword
DECLARE.
True or False? Mark for Review
(1) Points
True
False (*)
Correct
25. Which PL/SQL block type must return a value? Mark for Review
(1) Points
106
Anonymous
Function (*)
Procedure
Correct
Correct
27. Errors are handled in the Exception part of the PL/SQL block.
True
or False? Mark for Review
(1) Points
True (*)
False
Correct
107
two.) Mark for Review
(1) Points
DECLARE
END; (*)
EXCEPTION
BEGIN (*)
DBMS_OUTPUT.PUT_LINE
Correct
Executable
Exception
Declarative (*)
Definition
30. Which lines of code will correctly display the message "The
cat
sat on the mat"? (Choose two.) Mark for Review
(1) Points
108
Incorrect. Refer to Section 1.
Explicit (*)
Implicit
TO_CHAR
True
False (*)
109
An assignment statement must have a single semicolon at the end
(*)
Correct
True
False (*)
True (*)
False
TO_CHAR(sysdate)
TO_DATE(sysdate)
110
37. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of: Mark
for
Review
(1) Points
Character functions
Operators
111
v_string = 'Hello';
v_string := Hello;
v_date := 28-DEC-06;
Correct
True (*)
False
41. The following code will return the last name of the employee
whose
employee id is equal to 100: True or False?
DECLARE
v_last_name employees.last_name%TYPE;
employee_id employees.employee_id%TYPE := 100;
BEGIN
SELECT last_name INTO v_last_name
FROM employees
WHERE employee_id = employee_id;
END;
True
False (*)
112
Correct
SELECT *
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100;
(*)
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
113
Correct
SELECT salary
INTO v_result
FROM employees;
SELECT salary
INTO v_result
FROM employees
WHERE last_name ='Smith';
SELECT salary
INTO v_result
FROM employees
WHERE department_id = 80;
SELECT SUM(salary)
INTO v_result
FROM employees;
(*)
DESCRIBE employees;
114
UPDATE employees
SET last_name='Smith';
(*)
You have nothing new; the last ROLLBACK undid the INSERTs.
You have the rows added twice; there are four new rows.
Only one
115
48. PL/SQL extends SQL by including all of the following except:
Mark
for Review
(1) Points
variables
conditional statements
constants
declarative
nondeclarative
procedural (*)
low level
Correct
True (*)
False
116
1. Which of the following declarations is invalid? Mark for Review
(1) Points
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
Correct Correct
A table name.
3. 1. Null
2. False
3. True
4. 0
2 and 3
117
2, 3 and 4
1, 2 and 3 (*)
1, 2, 3 and 4
Correct Correct
BEGIN
INSERT INTO countries (id, name)
VALUES ('XA', 'Xanadu');
INSERT INTO countries (id, name)
VALUES ('NV','Neverland');
COMMIT;
COMMIT;
ROLLBACK;
END;
You have nothing new; the last ROLLBACK undid the INSERTs.
You have the rows added twice; there are four new rows.
118
All the DML statements in a single PL/SQL block
Correct Correct
Full Name
students_street_address (*)
v_code (*)
#hours
completion_%
Correct Correct
119
(Choose all correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
Identifiers (*)
Table Columns
Anonymous Blocks
SQL Workshop
Correct Correct
120
DECLARE
varA NUMBER := 12;
BEGIN
DECLARE
varB NUMBER := 8;
BEGIN
varA := varA + varB;
END;
DBMS_OUTPUT.PUT_LINE(varB);
END;
Mark for Review
(1) Points
12
20
VarB
Correct Correct
121
My
My name (*)
My name is
My name is Zeynep
Correct Correct
The inner block must be labeled, the outer block can be labeled.
DECLARE
x VARCHAR2(6) := 'Chang';
BEGIN
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
122
DBMS_OUTPUT.PUT_LINE(x);
END;
Mark for Review
(1) Points
Susan
Chang (*)
ChangChang
SusanChang
Correct Correct
<<outer_block>>
DECLARE
v_myvar NUMBER;
BEGIN
<<inner_block>>
DECLARE
v_myvar NUMBER := 15;
BEGIN
-- Line A
END;
END;
Mark for Review
(1) Points
v_myvar := 22;
<<outer_block>>.v_myvar := 22;
123
v_myvar(outer_block) := 22;
(*)
124
Specify the same number of variables in the INTO clause as database
columns in the SELECT clause.
Correct Correct
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary
INTO v_salary
FROM employees
WHERE employee_id=100;
(*)
SELECT v_salary
INTO salary
FROM employees
WHERE employee_id=100;
SELECT salary
FROM employees
INTO v_salary;
SELECT salary
FROM employees
WHERE employee_id=100
INTO v_salary;
125
Correct Correct
17. Which rows will be deleted from the EMPLOYEES table when
the following code is executed?
DECLARE
salary employees.salary%TYPE := 12000;
BEGIN
DELETE FROM employees
WHERE salary > salary;
END;
Mark for Review
(1) Points
No rows. (*)
DESCRIBE employees;
UPDATE employees
SET last_name='Smith';
(*)
126
DROP TABLE employees;
DECLARE
maxsalary NUMBER(7) = 5000;
Mark for Review
(1) Points
Correct.
Correct Correct
True (*)
False
Correct Correct
127
True (*)
False
Correct Correct
To comment code.
Correct Correct
True (*)
False
Correct Correct
128
True
False (*)
Correct Correct
declarative
nondeclarative
procedural (*)
low level
Correct Correct
PL/SQL and SQL can be used with many types of databases, including
Oracle.
129
with SQL statements. (*)
DECLARE (*)
BEGIN
EXCEPTION (*)
END;
Correct Correct
Correct Correct
130
29. Which of the following tools can NOT be used to develop
and test PL/SQL code? Mark for Review
(1) Points
Oracle Jdeveloper
Oracle iSQL*Plus
1. END;
2. EXCEPTION
3. DECLARE
4. BEGIN
2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
Correct Correct
131
DECLARE.
True or False? Mark for Review
(1) Points
True
False (*)
Correct Correct
Correct Correct
True (*)
False
Correct Correct
132
34. Which component of Oracle Application Express is used to
enter and run SQL statements and PL/SQL blocks? Mark for Review
(1) Points
Application Builder
Utilities
Object Browser
Correct Correct
Variables
LOBs (*)
DECLARE
TYPE dept_table_type IS TABLE OF departments%ROWTYPE INDEX BY
PLS_INTEGER; v_dept_table dept_table_type; ...
Mark for Review
(1) Points
133
Scalar
Composite (*)
LOB
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
set serveroutput on
DECLARE
a VARCHAR2(10) := '333';
b VARCHAR2(10) := '444';
c PLS_INTEGER;
d VARCHAR2(10);
BEGIN
134
c := TO_NUMBER(a) + TO_NUMBER(b);
d := a || b;
DBMS_OUTPUT.PUT_LINE(c);
DBMS_OUTPUT.PUT_LINE(d);
END;
Mark for Review
(1) Points
Correct Correct
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-04'; -- Point A
END;
Mark for Review
(1) Points
135
40. If today's date is 14th June 2007, which statement will
correctly convert today's date to the value: June 14, 2007 ? Mark
for
Review
(1) Points
TO_CHAR(sysdate)
TO_DATE(sysdate)
True
False (*)
Correct Correct
136
Nothing is wrong, the statement is fine
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
Mark for Review
(1) Points
81
49
14 (*)
18
Correct Correct
137
(Choose all correct answers)
v_string = 'Hello';
v_string := Hello;
v_date := 28-DEC-06;
Correct Correct
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
v_mybool := (v_mynumber BETWEEN 10 AND 20);
v_mybool := NOT (v_mybool);
END;
Mark for Review
(1) Points
True (*)
False
Correct Correct
138
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
'300'
300 (*)
NULL
Character functions
Operators
UPDATE employees
SET salary=salary*1.1;
Mark for Review
(1) Points
139
All employees get a 10% salary increase. (*)
An error message is displayed because you must use the INTO clause
to hold the new salary.
True
False (*)
True
140
False (*)
Null
Full Name
students_street_address (*)
v_code (*)
#hours
completion_%
Correct Correct
Identifiers (*)
141
Table Columns
Anonymous Blocks
SQL Workshop
They are optional but can make a PL/SQL block execute faster
Correct Correct
PL/SQL and SQL can be used with many types of databases, including
Oracle.
142
PL/SQL and SQL are both Oracle proprietary programming languages.
True (*)
False
Correct Correct
Processing
Procedural (*)
Primary
Proprietary
Correct Correct
143
the value of the variable cannot change. True or False? Mark for
Review
(1) Points
True (*)
False
Correct Correct
True (*)
False
True (*)
False
Correct Correct
144
(Choose all correct answers)
To comment code.
DECLARE
display_qty CONSTANT NUMBER;
Mark for Review
(1) Points
Correct.
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT)
END;
Mark for Review
(1) Points
A NULL is displayed.
145
A zero (0) is displayed. (*)
True
False (*)
UPDATE employees
SET salary=salary*1.1;
Mark for Review
(1) Points
An error message is displayed because you must use the INTO clause
to hold the new salary.
146
Incorrect Incorrect. Refer to Section 3.
A table name.
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
Correct Correct
17. 1. Null
2. False
3. True
4. 0
147
2 and 3
2, 3 and 4
1, 2 and 3 (*)
1, 2, 3 and 4
Correct Correct
DECLARE
varA NUMBER := 12;
BEGIN
DECLARE
varB NUMBER := 8;
BEGIN
varA := varA + varB;
END;
DBMS_OUTPUT.PUT_LINE(varB);
END;
Mark for Review
(1) Points
12
20
VarB
148
Correct Correct
True (*)
False
20. When nested blocks are used, which blocks can or must be
labeled? Mark for Review
(1) Points
The inner block must be labeled, the outer block can be labeled.
DECLARE
var_a NUMBER := 6;
var_b DATE;
BEGIN
var_a := var_a * 2;
var_b := '28 December 2006'; -- Line A
var_a := var_a * 2;
EXCEPTION
WHEN OTHERS THEN
149
DBMS_OUTPUT.PUT_LINE(var_a);
END;
Mark for Review
(1) Points
12 (*)
24
Correct Correct
150
Scalar
Composite
Reference
LOB (*)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
Correct Correct
151
values for a variable. (*)
If Oracle changes the conversion rules in the future, your code may
not work any more (*)
v_string = 'Hello';
v_string := Hello;
152
v_number := 17 + 34; (*)
v_date := 28-DEC-06;
True
False (*)
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-04'; -- Point A
END;
Mark for Review
(1) Points
153
Incorrect Incorrect. Refer to Section 2.
True
False (*)
31. Examine the following code. What is the final value of V_MYBOOL
?
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
v_mybool := (v_mynumber BETWEEN 10 AND 20);
v_mybool := NOT (v_mybool);
END;
Mark for Review
(1) Points
True (*)
False
154
set serveroutput on
DECLARE
a VARCHAR2(10) := '333';
b VARCHAR2(10) := '444';
c PLS_INTEGER;
d VARCHAR2(10);
BEGIN
c := TO_NUMBER(a) + TO_NUMBER(b);
d := a || b;
DBMS_OUTPUT.PUT_LINE(c);
DBMS_OUTPUT.PUT_LINE(d);
END;
Mark for Review
(1) Points
Correct Correct
Character functions
Operators
Correct Correct
155
34. If today's date is 14th June 2007, which statement will
correctly convert today's date to the value: June 14, 2007 ? Mark
for
Review
(1) Points
TO_CHAR(sysdate)
TO_DATE(sysdate)
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
'300'
300 (*)
NULL
Correct Correct
156
Previous Page 7 of 10 Next Summary
Only one
BEGIN
INSERT INTO countries (id, name)
VALUES ('XA', 'Xanadu');
INSERT INTO countries (id, name)
VALUES ('NV','Neverland');
COMMIT;
COMMIT;
ROLLBACK;
END;
You have nothing new; the last ROLLBACK undid the INSERTs.
You have the rows added twice; there are four new rows.
157
Incorrect Incorrect. Refer to Section 3.
Correct Correct
39. Which rows will be deleted from the EMPLOYEES table when
the following code is executed?
DECLARE
salary employees.salary%TYPE := 12000;
BEGIN
DELETE FROM employees
WHERE salary > salary;
END;
Mark for Review
(1) Points
No rows. (*)
158
Incorrect Incorrect. Refer to Section 3.
DESCRIBE employees;
UPDATE employees
SET last_name='Smith';
(*)
DECLARE
v_result employees.salary%TYPE;
BEGIN
SELECT salary
INTO v_result
FROM employees;
SELECT salary
INTO v_result
159
FROM employees
WHERE last_name ='Smith';
SELECT salary
INTO v_result
FROM employees
WHERE department_id = 80;
SELECT SUM(salary)
INTO v_result
FROM employees;
(*)
DECLARE
v_holdit employees.last_name%TYPE;
BEGIN ...
SELECT *
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100;
(*)
160
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
True (*)
False
Correct Correct
Executable
Exception
Declarative (*)
Definition
Correct Correct
161
BEGIN
DBMS_OUTPUT.PUT_LINE('My first quiz');
END;
Mark for Review
(1) Points
procedure
subroutine
function
anonymous (*)
True
False (*)
Correct Correct
162
To store new rows in the database
Correct Correct
DECLARE (*)
BEGIN
EXCEPTION (*)
END;
Correct Correct
Anonymous
Function (*)
Procedure
Correct Correct
163
(1) Points
Oracle Jdeveloper
Oracle iSQL*Plus
Correct Correct
False (*)
Null
No rows are modified because you did not specify "WHERE department_id=10"
An error message is displayed because you must use the INTO clause to hold the new
salary.
Correct
164
3. You declare an implicit cursor in the DECLARE section of a PL/SQL block. True
or False? Mark for Review
(1) Points
True
False (*)
SELECT salary
INTO v_result
FROM employees
WHERE last_name ='Smith';
SELECT salary
INTO v_result
FROM employees
WHERE department_id = 80;
SELECT SUM(salary)
INTO v_result
FROM employees;
(*)
False (*)
165
Correct
6. Which one of these SQL statements can be directly included in a PL/SQL
executable block? Mark for Review
(1) Points
SELECT last_name FROM employees
WHERE employee_id=100;
DESCRIBE employees;
UPDATE employees
SET last_name='Smith';
(*)
Correct
7. Which of the following is NOT a good guideline for retrieving data in PL/SQL?
Mark for Review
(1) Points
Declare the receiving variables using %TYPE
Specify the same number of variables in the INTO clause as database columns in the
SELECT clause.
Correct
9. What is the output when the following program is executed?
set serveroutput on
DECLARE
a VARCHAR2(10) := '333';
166
b VARCHAR2(10) := '444';
c PLS_INTEGER;
d VARCHAR2(10);
BEGIN
c := TO_NUMBER(a) + TO_NUMBER(b);
d := a || b;
DBMS_OUTPUT.PUT_LINE(c);
DBMS_OUTPUT.PUT_LINE(d);
END;
Mark for Review
(1) Points
Nothing. The code will result in an error.
Correct
10. Single row character functions are valid SQL functions in PL/SQL. True or
False? Mark for Review
(1) Points
True (*)
False
Correct
11. What is wrong with this assignment statement?
myvar := 'To be or not to be';
Correct
12. Which of the following are valid assignment statements? (Choose two.)
Mark for Review
(1) Points (Choose all correct answers)
v_string = 'Hello';
167
v_string := Hello;
v_date := 28-DEC-06;
False (*)
Implicit
TO_CHAR
Correct
15. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of: Mark for
Review
(1) Points
Implicit conversion functions
Character functions
Operators
Correct
16. Examine the following code. What is the final value of V_MYBOOL ?
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
v_mybool := (v_mynumber BETWEEN 10 AND 20);
v_mybool := NOT (v_mybool);
END;
Mark for Review
(1) Points
168
True (*)
False
Correct
17. PL/SQL can convert a VARCHAR2 value containing alphabetic characters to a
NUMBER value. True or False? Mark for Review
(1) Points
True
False (*)
49
14 (*)
18
Correct
19. Reserved words can be used as identifiers. True or False? Mark for Review
(1) Points
True
False (*)
Table Columns
Anonymous Blocks
SQL Workshop
169
Incorrect. Refer to Section 2.
21. Which of the following are valid identifiers? (Choose two.) Mark for
Review
(1) Points (Choose all correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
Correct
22. Examine the following code. At Line A, we want to assign a value of 22 to the
outer block's variable v_myvar. What code should we write at Line A?
<<outer_block>>
DECLARE
v_myvar NUMBER;
BEGIN
<<inner_block>>
DECLARE
v_myvar NUMBER := 15;
BEGIN
-- Line A
END;
END;
Mark for Review
(1) Points
outer_block.v_myvar := 22; (*)
v_myvar := 22;
<<outer_block>>.v_myvar := 22;
v_myvar(outer_block) := 22;
We cannot reference the outer block's variable because both variables have the same
name
Correct
23. An exception occurs within the inner block of two nested blocks. The inner
block does not have an EXCEPTION section. What always happens? Mark for Review
(1) Points
Both blocks fail and an error message is displayed by the calling environment
170
Oracle automatically tries to re-execute the inner block
12
20
VarB
Correct
25. In the following code, Line A causes an exception. What value will be displayed
when the code is executed?
DECLARE
outer_var VARCHAR2(50) := 'My';
BEGIN
outer_var := outer_var || ' name';
DECLARE
inner_var NUMBER;
BEGIN
inner_var := 'Mehmet'; -- Line A
outer_var := outer_var || ' is';
END;
outer_var := outer_var || ' Zeynep';
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(outer_var);
END;
Mark for Review
(1) Points
My
171
My name (*)
My name is
My name is Zeynep
Correct
26. What will be displayed when the following code is executed?
DECLARE
x VARCHAR2(6) := 'Chang';
BEGIN
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
DBMS_OUTPUT.PUT_LINE(x);
END;
Mark for Review
(1) Points
Susan
Chang (*)
ChangChang
SusanChang
Correct
27. Assignment statements can continue over several lines in PL/SQL. True or
False? Mark for Review
(1) Points
True (*)
False
Correct
28. Variables can be assigned a value in both the Executable and Declaration
sections of a PL/SQL program. True or False? Mark for Review
(1) Points
True (*)
False
172
To store data values. (*)
To comment code.
False
Correct
31. Identify which of the following assignment statements are valid. (Choose three.)
Mark for Review
(1) Points (Choose all correct answers)
v_last_name := Chandra;
Identifier
Delimiter
Composite (*)
LOB (*)
Correct
33. What is the data type of the variable V_DEPT_TABLE in the following
declaration?
DECLARE
TYPE dept_table_type IS TABLE OF departments%ROWTYPE INDEX BY
PLS_INTEGER; v_dept_table dept_table_type; ...
Mark for Review
(1) Points
Scalar
173
Composite (*)
LOB
LOBs (*)
Correct
35. Every PL/SQL anonymous block must start with the keyword DECLARE. True
or False? Mark for Review
(1) Points
True
False (*)
END; (*)
EXCEPTION
BEGIN (*)
DBMS_OUTPUT.PUT_LINE
Correct
37. Errors are handled in the Exception part of the PL/SQL block. True or False?
Mark for Review
(1) Points
True (*)
False
Correct
38. Which PL/SQL block type must return a value? Mark for Review
(1) Points
Anonymous
Function (*)
174
Procedure
3,4,2,1 (*)
3,2,4,1
4,3,2,1
Correct
40. Which lines of code will correctly display the message "The cat sat on the mat"?
(Choose two.) Mark for Review
(1) Points (Choose all correct answers)
DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)
subroutine
function
anonymous (*)
Correct
42. Which of the following tools can NOT be used to develop and test PL/SQL
code? Mark for Review
175
(1) Points
Oracle Jdeveloper
Oracle iSQL*Plus
college_name VARCHAR2(20):='Harvard';
2, 3 and 4
1, 2 and 3 (*)
1, 2, 3 and 4
False
176
VALUES ('NV','Neverland');
COMMIT;
COMMIT;
ROLLBACK;
END;
What happens when the block of code finishes?
Mark for Review
(1) Points
You have nothing new; the last ROLLBACK undid the INSERTs.
You have the rows added twice; there are four new rows.
A related set of SQL DML statements which must be executed either completely or not at
all (*)
PL/SQL and SQL can be used with many types of databases, including Oracle.
PL/SQL allows basic program logic and control flow to be combined with SQL
statements. (*)
nondeclarative
177
procedural (*)
low level
Correct
50. The P in PL/SQL stands for: Mark for Review
(1) Points
Processing
Procedural (*)
Primary
Proprietary
Correct
2. You want to repeat a set of statements 100 times, incrementing a counter each time.
What kind of PL/SQL control structure would you use?
IF...THEN...ELSE
IF...THEN...ELSIF...ELSE
CASE...WHEN...THEN
A loop. (*)
IF (v_job='President')
THEN v_salary := 10000;
178
END IF;
DBMS_OUTPUT.PUT_LINE(mature);
child
teenager
adult (*)
adultteenagerchild
5. What will be displayed when this block is executed? DECLARE v_bool1 BOOLEAN
:= TRUE; v_bool2 BOOLEAN; v_char VARCHAR(4) := 'up'; BEGIN IF (v_bool1 AND
v_bool2) THEN v_char:='down'; ELSE v_char:='left'; END IF;
DBMS_OUTPUT.PUT_LINE(v_char); END;
up
down
left (*)
null
6. What will be displayed when this block is executed? DECLARE v_bool1 BOOLEAN
:= NULL; v_bool2 BOOLEAN := NULL; v_char VARCHAR(10) := 'Start'; BEGIN IF
(v_bool1 = v_bool2) THEN v_char:='Equal'; ELSE v_char:='Not equal'; END IF;
DBMS_OUTPUT.PUT_LINE(v_char); END;
Equal
Not equal (*)
Start
Nothing will be displayed. The block will fail because
you cannot compare two null values.
8. Which of the following statements are true about PL/SQL conditional control
structures such as IF ... , CASE ... and loops?
179
1. Examine the following code:
DECLARE
v_score NUMBER(3);
v_grade CHAR(1);
BEGIN
v_grade := CASE v_score
-- Line A
....
The CASE expression must convert a numeric score to a letter grade: 90 -> A, 80 -> B, 70 ->
C and so on. What should be coded at Line A?
DECLARE
v_age NUMBER(3);
v_gender VARCHAR2(6) := 'Female';
v_status VARCHAR2(20);
BEGIN
CASE
WHEN v_age >= 18 AND v_gender = 'Male' THEN v_status := 'Adult Male';
WHEN v_age >= 18 AND v_gender = 'Female' THEN v_status := 'Adult Female';
WHEN v_age < 18 AND v_gender = 'Male' THEN v_status := 'Junior Male';
WHEN v_age < 18 AND v_gender = 'Female' THEN v_status := 'Junior Female';
ELSE v_status := 'Other Value';
END CASE;
DBMS_OUTPUT.PUT_LINE(v_status);
END;
Adult Male
Junior Female
Other Value (*)
Nothing will be displayed because V_STATUS is set to
NULL.
DECLARE
v_age1 NUMBER(3);
v_age2 NUMBER(3);
v_message VARCHAR2(20);
BEGIN
CASE
180
WHEN v_age1 = v_age2 THEN v_message := 'Equal';
WHEN v_age1 <> v_age2 THEN v_message := 'Unequal';
ELSE v_message := 'Undefined';
END CASE;
DBMS_OUTPUT.PUT_LINE(v_message);
END;
Equal
Undefined (*)
Unequal
Nothing will be displayed because V_MESSAGE is set
to NULL.
DECLARE
v_a BOOLEAN;
v_b BOOLEAN := FALSE;
v_c BOOLEAN ;
BEGIN
v_c := (v_a AND v_b);
-- Line A
....
END;
True
False (*)
NULL
Undefined
DECLARE
x BOOLEAN := FALSE;
y BOOLEAN := FALSE;
z BOOLEAN ;
BEGIN
z := (x OR NOT y);
-- Line A
....
END;
True (*)
False
NULL
181
An error will occur because you cannot combine two
Boolean variables using "NOT".
DECLARE
v_score NUMBER(3);
v_grade CHAR(1);
BEGIN
CASE v_score
-- Line A
....
The CASE statement must convert a numeric score to a letter grade: 90 -> A, 80 -> B, 70 -> C
and so on.
END; (*)
ENDIF;
END CASE;
ENDCASE;
END;
END CASE; (*)
END IF;
ENDCASE;
1. You want to calculate and display the multiplication table for "sevens":
7x1=7, 7x2=14, 7x3=21 and so on. Which kind of PL/SQL construct is best for this? Mark
for Review
(1) Points
A loop (*)
182
A CASE statement
IF ... END IF;
A Boolean variable.
2. What are the three kinds of loops in PL/SQL? Mark for Review
(1) Points
i := 10;
LOOP
i := i + 1;
EXIT WHEN i > 30;
END LOOP; Mark for Review
(1) Points
A FOR loop.
A WHILE loop.
A basic loop. (*)
An infinite loop.
A nested loop.
4. How many EXIT statements can be coded inside a basic loop? Mark
for Review
(1) Points
None.
One only.
Two.
As many as you need, there is no limit. (*)
DECLARE
v_count NUMBER := 10;
v_result NUMBER;
BEGIN
LOOP
v_count := v_count - 1;
EXIT WHEN v_count < 5;
v_result := v_count * 2;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_result);
183
END;
Mark for Review
(1) Points
8
10 (*)
12
NULL
6. For which one of these tasks should you use a PL/SQL loop? Mark
for Review
(1) Points
DECLARE
v_count NUMBER := 0;
v_string VARCHAR2(20);
BEGIN
LOOP
v_string := v_string || 'x';
IF LENGTH(v_string) > 10 THEN
EXIT;
END IF;
v_count := v_count + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_count);
END;
What will be displayed when this block is executed? Mark for Review
(1) Points
9
10 (*)
11
xxxxxxxxxxx
DECLARE
v_bool BOOLEAN := TRUE;
184
v_date DATE;
BEGIN
LOOP
EXIT WHEN v_bool;
SELECT SYSDATE INTO v_date FROM dual;
END LOOP;
END;
How many times will the SELECT statement execute? Mark for Review
(1) Points
Once.
Twice.
Never (the SELECT will not execute at all) (*)
An infinite number of times because the EXIT condition will
never be true
2. You want a loop that counts backwards from 10 through 1. How do you code that?
FOR i IN 10 .. 1 LOOP
FOR i IN 1 .. 10 BY -1 LOOP
FOR i IN REVERSE 1 .. 10 LOOP (*)
FOR i IN REVERSE 10 .. 1 LOOP
3. In a WHILE loop, the controlling condition is checked at the start of each iteration.
True or False?
True (*)
False
185
4. You should use a WHILE loop when the number of iterations of the loop is known in
advance. True or False? Mark for Review
(1) Points
True
False (*)
i := 2;
WHILE i < 3 LOOP
i := 4;
DBMS_OUTPUT.PUT_LINE('The counter is: ' || i);
END LOOP;
DECLARE
v_date DATE := SYSDATE;
BEGIN
WHILE v_date < LAST_DAY(v_date) LOOP
v_date := v_date + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_date);
END;
If today's date is 17th April 2007, what will be displayed when this block executes?
01-MAY-07
31-DEC-07
186
4/30/2007 (*)
4/17/2007
DECLARE
v_blue NUMBER(3) := 0;
v_red NUMBER(3) := 0;
BEGIN
<<blue>> LOOP
v_blue := v_blue + 1;
EXIT WHEN v_blue > 10;
<<red>> LOOP
v_red := v_red + 1;
EXIT WHEN v_red > 10;
-- Line A
END LOOP red;
END LOOP blue;
END;
What should you code at Line A to exit from the outer loop?
EXIT;
EXIT red;
EXIT <<blue>>;
EXIT blue; (*)
DECLARE
x NUMBER(6) := 0 ;
BEGIN
FOR i IN 1..10 LOOP
FOR j IN 1..5 LOOP
x := x+1 ;
END LOOP;
END LOOP;
DBMS_OUTPUT.PUT_LINE(x);
187
END;
5
10
15
50 (*)
4. When the following code is executed, how many lines of output will be displayed?
BEGIN
FOR i IN 1..5 LOOP
FOR j IN 1..8 LOOP
DBMS_OUTPUT.PUT_LINE(i || ',' || j);
END LOOP;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
80
45 (*)
14
41
B, E, A, C, D (*)
E, B, A, C, D
B, E, A, D, C
B, A, E, D, C
188
3. When must you declare and use an explicit cursor?
4. Which of the following best describes the difference between implicit and explicit
cursors?
DECLARE
CURSOR dept_curs IS SELECT department_name FROM departments;
v_dept_name departments.department_name%TYPE;
BEGIN
OPEN dept_curs;
LOOP
FETCH dept_curs INTO v_dept_name;
DBMS_OUTPUT.PUT_LINE(v_dept_name);
EXIT WHEN dept_curs%NOTFOUND;
END LOOP;
CLOSE dept_curs;
END;
There are 10 rows in the DEPARTMENTS table. What will happen when this code is executed?
189
The loop will execute for ever; the same 10 rows will be
displayed over and over again.
DECLARE
CURSOR dept_curs IS SELECT department_name FROM departments;
v_dept_name departments.department_name%TYPE;
BEGIN
OPEN dept_curs;
LOOP
FETCH dept_curs INTO v_dept_name;
EXIT WHEN dept_curs%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_dept_name);
CLOSE dept_curs;
END LOOP;
END;
DECLARE
CURSOR emp_curs IS SELECT last_name FROM employees;
v_last_name employees.last_name%TYPE;
BEGIN
OPEN emp_curs;
LOOP -- Point A
FETCH emp_curs INTO v_last_name;
EXIT WHEN emp_curs%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_last_name);
END LOOP;
CLOSE emp_curs;
END;
At Point A (after you have OPENed the cursor) another user updates an employee's last_name
from 'Smith' to 'Jones' and immediately COMMITs.
When your block FETCHes this row, which value will be fetched and displayed?
1
Smith (*)
Jones
Smith and Jones (the row will be fetched twice)
190
An INVALID_CURSOR exception will be raised when you try
to FETCH the row.
9. There are 8 countries in REGION_ID 13 (Central America). What will happen when
the following code is executed?
DECLARE
CURSOR country_curs IS SELECT country_name FROM wf_countries
WHERE region_id = 13;
v_country_name wf_countries.country_name%TYPE;
BEGIN
OPEN country_curs;
WHILE country_curs%FOUND
LOOP
FETCH country_curs INTO v_country_name;
DBMS_OUTPUT.PUT_LINE(v_country_name);
END LOOP;
CLOSE country_curs;
END;
10. Which one of the following explicit cursor declarations is NOT valid?
CURSOR country_curs IS
SELECT country_name, region_name
FROM wf_countries c, wf_world_regions r
WHERE c.region_id = r.region_id;
CURSOR country_curs IS
SELECT country_name INTO v_country_name
FROM wf_countries;
(*)
CURSOR country_curs IS
SELECT country_name
FROM wf_countries
ORDER BY population DESC;
CURSOR country_curs IS
SELECT country_name
191
FROM wf_countries
WHERE region_id IN
(SELECT region_id FROM wf_world_regions
WHERE LOWER(region_name) LIKE '%asia%');
11. One (and only one) employee has LAST_NAME = 'Grant'. You need to code:
DECLARE
CURSOR emp_curs IS SELECT last_name, salary FROM employees;
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
FETCH emp_curs INTO v_last_name, v_salary;
OPEN emp_curs;
FETCH emp_curs INTO v_last_name, v_salary;
CLOSE emp_curs;
END;
When FETCHing more than one row, you MUST use a loop.
The cursor declaration does not include a WHERE condition.
The cursor declaration does not include an INTO clause.
The first row is FETCHed before the cursor is OPENed. (*)
True
False (*)
2. Which of the following explicit cursor attributes evaluates to TRUE if the most recent
FETCH returns a row?
%ISOPEN
%NOTFOUND
192
%FOUND (*)
%ROWCOUNT
3. Look at these declarations:
DECLARE
CURSOR dept_loc_cursor IS
SELECT department_id, department_name, location_name
FROM departments d, locations l
WHERE d.location_id = l.location_id;
v_dept_loc dept_loc_cursor%ROWTYPE;
4. How must you reference one field which is part of a PL/SQL record?
field_name.record_name
record_name.field_name (*)
record_name(field_name)
field_name OF record_name
It cannot be done.
DECLARE
CURSOR emp_cursor IS
SELECT employee_id, last_name, salary FROM employees;
v_empcurs emp_cursor%ROWTYPE;
Scalar
Record (*)
Cursor
Row
DECLARE
CURSOR country_curs IS
SELECT country_id, country_name
FROM wf_countries
ORDER BY country_name;
v_country country_curs%ROWTYPE;
BEGIN
OPEN country_curs;
LOOP
193
FETCH country_curs INTO v_country;
EXIT WHEN country_curs%NOTFOUND;
------- Line A
END LOOP;
CLOSE country_curs;
END;
You want to display the id and name of each FETCHed country. What would you code at Line
A?
CURSOR country_curs IS
SELECT * FROM wf_countries
ORDER BY country_name;
There are over 200 rows in the WF_COUNTRIES table, but you want to fetch and display only
the first 25 rows.
BEGIN
FOR emp_record IN emp_cursor LOOP
DBMS_OUTPUT.PUT_LINE(emp_record.last_name);
194
END LOOP;
IF emp_record.last_name = 'Patel' THEN ...
5. Which one of the following is a valid cursor FOR loop with a subquery?
DECLARE
CURSOR emp_cursor IS SELECT * FROM employees;
BEGIN
FOR emp_record IN emp_cursor LOOP
DBMS_OUTPUT.PUT_LINE( --Point A -- );
END LOOP;
END;
195
To display the salary of an employee, what code should you write at Point A?
emp_record.salary (*)
emp_cursor.salary
employees.salary
emp_record.employees.salary
TO_CHAR(salary)
True (*)
False
2. The following cursor has been declared:
CURSOR emp_curs
(p_dept_id employees.department_id%TYPE,
p_job_id employees.job_id%TYPE) IS
SELECT * FROM employees
WHERE department_id = p_dept_id
AND job_id = p_job_id;
OPEN emp_curs(20);
FOR emp_rec IN emp_curs(20) LOOP ...
OPEN emp_curs('IT_PROG', 20);
FOR emp_rec IN emp_curs(20,'IT_PROG') LOOP ... (*)
FOR emp_rec IN emp_curs(p_dept_id p_job_id) LOOP ...
3. You want to use explicit cursors to fetch and display all the countries in a specific
region. There are 19 rows in the WF_WORLD_REGIONS table. You want to use a different
region each time the cursor is opened. How many cursors should you declare?
DECLARE
CURSOR emp_curs (p_dept_id employees.department_id%TYPE) IS
SELECT * FROM employees
WHERE department_id = p_dept_id;
196
v_emp_rec emp_curs%ROWTYPE;
v_deptid NUMBER(4) := 50;
BEGIN
OPEN emp_curs( -- Point A --);
....
You want to open the cursor, passing value 50 to the parameter. Which of the following are
correct at Point A?
50
v_deptid
100 / 2
All of the above. (*)
--Block A
DECLARE
CURSOR emp_cursor IS
SELECT employee_id, last_name
FROM employees
WHERE department_id = 80
FOR UPDATE OF salary;
--Block B
DECLARE
CURSOR emp_cursor IS
SELECT employee_id, last_name
FROM employees
WHERE department_id = 80
FOR UPDATE OF salary
NOWAIT;
197
In Block A, the program waits indefinitely until the rows are available. In Block B, the program
returns control immediately so that it can do other work. (*)
In Block A, the program waits indefinitely until the rows are available. In Block B, control is
returned to your program after 5 seconds so that it can do other work.
CURSOR country_curs IS
SELECT country_id, country_name
FROM wf_countries
FOR UPDATE WAIT 10;
Another user updates a row in WF_COUNTRIES but does not COMMIT the update. What will
happen when you OPEN country_curs; ? Mark for Review
(1) Points
4. You want to fetch rows from the EMPLOYEES table. You want to lock the fetched
rows, to prevent other users from updating them.
You declare the following cursor:
CURSOR emp_curs IS
SELECT employee_id, last_name, salary
FROM employees
-- Line A -- ;
FOR LOCK
FOR UPDATE OF employees
FOR UPDATE (*)
198
FOR UPDATE (employees)
CURSOR emp_dept_curs IS
SELECT last_name, salary, department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id
-- Point A -- ;
You want to lock fetched rows from EMPLOYEES, but NOT lock fetched rows from
DEPARTMENTS.
FOR UPDATE
FOR UPDATE of salary (*)
FOR UPDATE OF employees
FOR UPDATE (last_name)
7. You have declared a cursor as SELECT .... FOR UPDATE; You have OPENed the
cursor and locked the FETCHed rows. When are these row locks released?
199
1. You want to produce a report which displays each department and (immediately after
each department) a list of employees who work in that department. You declare a
DEPARTMENTS cursor as:
CURSOR dept_curs IS
SELECT * FROM departments
ORDER BY department_id;
DECLARE
CURSOR region_cur IS
SELECT * FROM wf_world_regions;
v_region_rec region_cur%ROWTYPE;
CURSOR country_cur (p_region_id NUMBER) IS
SELECT * FROM wf_countries
WHERE region_id = p_region_id;
v_country_rec country_cur%ROWTYPE;
BEGIN
OPEN region_cur;
LOOP
FETCH region_cur INTO v_region_rec;
EXIT WHEN region_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE
(v_region_rec.region_name);
-- Line A --
LOOP
FETCH country_cur INTO v_country_rec;
EXIT WHEN country_cur%NOTFOUND;
......
200
3. Which of the following is a good reason to use two cursors in a single PL/SQL block?
4. Assume that table BIGDEPTS contains 100 rows, and table BIGEMPS contains 1000
rows, with 10 employees in each department. Consider the following code:
DECLARE
CURSOR bigdept_cur IS
SELECT * FROM bigdepts;
CURSOR bigemp_cur IS
SELECT * FROM bigemps;
BEGIN
FOR dept_rec IN bigdept_cur LOOP
DBMS_OUTPUT.PUT_LINE
(dept_rec.department_name);
FOR emp_rec IN bigemp_cur LOOP
IF emp_rec.department_id=dept_rec.department_id
THEN DBMS_OUTPUT.PUT_LINE
(emp_rec.last_name);
END IF;
END LOOP;
END LOOP;
END;
5. Assume your schema contains 25 tables. How many explicit cursors can you declare
and use within a single PL/SQL block?
Only one.
As many as you need - there is no limit. (*)
201
A maximum of three.
As many as you need, but only one of them can be open at any
time.
A maximum of 25 (one for each table in your schema).
6. Which of the following is NOT allowed when using multiple cursors with parameters?
Himb
Test: Quiz 1: Introduction to PL/SQL
Section 1
1. Which of the following statements is true? Mark for Review (1) Points
PL/SQL is an Oracle proprietary, procedural, 3GL Adevarat
PL/SQL is an Oracle proprietary, procedural, 4GL programming language.
PL/SQL is an Oracle proprietary, nonprocedural, 3GL programming language.
PL/SQL is an ANSI-compliant, procedural programming language.
4. Nonprocedural languages allow the programmer to produce a result when a series of steps are followed. True or
False?
True False (*)
5. In which three ways does PL/SQL extend the SQL programming language
By adding procedural constructs. (*)
By adding compound constructs.
By adding iterative control. (*)
By adding conditional control. (*)
202
2. Procedural constructs give you better control of your SQL statements and their execution. True or False?
True (*)
False
3. PL/SQL differs from C and Java in which of the following ways? (Choose two.)
It requires an Oracle database or tool. (*)
It does not support object-oriented programming.
It is the most efficient language to use with an Oracle database. (*)
It is the most complex programming language to learn.
It is not portable to other operating systems.
4. Which of the following can be compiled as a standalone program outside the database?
A program developed in PL/SQL
A program developed in Java
A program developed in C
All the above
Programs developed in Java or C, but not in PL/SQL. (*)
6. You can create a Web site application written entirely in PL/SQL. True or False?
True (*)
False
DECLARE
BEGIN (*)
EXCEPTION
END; (*)
DECLARE (*)
END
Unamed (*)
203
Not stored in the database
SQL*Plus
gSQL*Plus (*)
Oracle Cdeveloper
Java*Plus
PL/SQL Express
Exception only
Executable only
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello');
DBMS_OUTPUT.PUT_LINE(' and Goodbye');
The Declaration section is missing
9. How can you display results to check that a PL/SQL block is working correctly?
10. Which lines of code will correctly display the message "Hello World" ? (Choose two.)
204
DBMS_OUTPUT('Hello World');
DBMS_OUTPUT.PUT_LINE('Hello' || 'World');
1. If you want to SELECT all the columns of data in a table, you use which of the following symbols?
&
* (*)
2. What SQL statement will return the ID, name, and area of all countries in the WF_COUNTRIES table, listed in
order of greatest area to least area?
3. Which of the following statements lists each employee's employee_id, salary, and salary plus a 20 percent bonus?
4. Which of the following statements diplays the population of the Republic of Benin (country_id 229) after a 3
percent growth in its population?
205
FROM wf_countries
WHERE country_id=229;
5. What can you use to change the column heading of calculated values in a SQL statement?
Multiplication operator
Concatenation operator
How would you modify this statement to display "Country", "Population", and "Expected Growth" as the column headings?
8. The F_FOOD_ITEMS table contains the FOOD_ITEM_NUMBER and the REGULAR_CODE columns. Which
statement would display the FOOD_ITEM_NUMBER joined with the REGULAR_CODE without any space in between
them?
206
FROM f_food_items;
SELECT food_item_numberregularcode
FROM f_food_items;
9. Which of the following statements will display a sentence such as the following:
Aruba has an area of 193.
for every country in the WF_COUNTRIES table?
SELECT country_name " has an area of " area "." FROM wf_countries;
10. Which of the following statements will generate a sentence such as the following:
The national holiday for United Arab Emirates is Independence Day.
for every country in the WF_COUNTRIES table?
SELECT 'The national holiday for '|| country_name || ' is ' || national_holiday_name
FROM wf_countries;
SELECT "The national holiday for "|| country_name || " is " || national_holiday_name || "."
FROM wf_countries;
SELECT 'The national holiday for '|| country_name || ' is ' || national_holiday_name || '.'
FROM wf_countries; (*)
11. Which statement would display the departments in the EMPLOYEES table without displaying any duplicates?
SELECT department_id
FROM employees;
ELECT department_id
FROM employees
having ROWID=1;
207
12. When using the LIKE operator, the "%" and "_" symbols can be used to do a pattern-matching, wild card search.
True or False? True (*) False
13. Which statement would select salaries that are greater than or equal to 2500 and less than or equal to 3500? Choose
two correct answers.
2. Which SQL statement will display each country's name with the first letter (only) of each word in uppercase?
SELECT UPPER(country_name)
FROM wf_countries;
SELECT lower(country_name)
FROM wf_countries;
SELECT INITCAP(country_name)
FROM wf_countries; (*)
SELECT country_name
FROM wf_countries
ORDER BY INITCAP(country_name);
3. Which statement returns a user password combining the ID of an employee and the first 4 characters of their last
name?
SELECT CONCAT (employee_id, SUBSTR(last_name,4,1))
AS "User Passwords"
FROM employees;
208
4. What is returned by the following statement?
SELECT CONCAT('Today is','Thursday!') FROM DUAL;
TodayisThursday!
today is thursday!
Today is Thursday!
6. The following SQL statement will display the value: 456. True or False?
SELECT TRUNC(ROUND(456.98))
FROM dual;
True False (*)
7. Assume that today is January 10, 2008. What would be the output of the following statement?
SELECT TO_CHAR(SYSDATE, 'ddth "of" Month, YYYY') FROM DUAL;
10th of January, 2008 (*)
10 January, 2008
10-January-2008
January 10th, 2008
8. Assume that today is December 31, 2007. What would be the output of the following statement?
SELECT TO_CHAR(SYSDATE, 'DD/MM/Y') FROM DUAL;
12/31/7
31-12-07
31/12/2007
31/12/7 (*)
9. What function would you use to return the highest date in a month?
FINAL_DAY
END_DAY
HIGHEST_DAY
LAST_DAY (*)
10. Which query would return a whole number if today's date is 26-MAY-04?
SELECT TRUNC(MONTHS_BETWEEN(SYSDATE,'19-MAR-79') /12)
AS YEARS
FROM DUAL; (*)
209
12. NULL means the same thing as a space or 0 (zero). True or False?
True
False (*)
2. Which of the following are required when declaring a variable? (Choose two.)
Identifier name (*)
CONSTANT
Data type (*)
NOT NULL
210
All of the above. (*)
3. Which of the following is a valid naming convention for an identifier? (Choose two.)
Can include letters or numbers (*)
Cannot contain a reserved word (*)
Can be over 30 characters
Can start with a number or special character
??
*/ / *
:: ::
/* */ (*)
211
Lexical
Scalar (*)
Delimiter
Composite (*)
5. What are the data types of the variables in the following declaration?
DECLARE
fname VARCHAR2(20);
fname VARCHAR2(15) DEFAULT 'fernandez';
BEGIN
...
Scalar (*)
Composite
LOB
2. Which of the following variable declarations does NOT use a number data type?
v_count PLS_INTEGER := 0;
v_median_age NUMBER(6,2);
v_students LONG; (*)
v_count BINARY_INTEGER;
212
3. Code is easier to read if you declare one identifier per line. True or False?
True (*)
False
4. If you use the %TYPE attribute, you can avoid hard-coding the column name. True or
False? True
False (*)
5. When declared using %TYPE, a variable will inherit ____ from the column on which
it is based.
2. Table aliases can be used to shorten the syntax in join statements. True or False?
True (*)
False
3. A nonequijoin combines tables that have one or more exact matching columns. True or
False?
True
False (*)
213
4. What kind of join is used in the following example?
Simple join
Equijoin
Nonequijoin (*)
Outer join
5. What type of join returns rows for one table even when there are no matching rows in
the other table?
Simple join
Equijoin
Nonequijoin
Outer join (*)
7. When a join condition is omitted completely the result is a Cartesian product in which
all combinations of rows will be displayed. True or False?
True (*)
False
8. If table A has 20 rows and table B has 10 rows, how many rows will be returned if you
perform a Cartesian product on those two tables? Mark for Review
(1) Points
20
10
200 (*)
120
214
Test: Quiz 6: Review of SQL Group Functions and Subqueries
1. What would the following SQL statement return?
SELECT MAX(hire_date) FROM employees;
The hire date of the longest serving employee.
The hire date of the newest (most recently hired) employee. (*)
The hire dates of all employees in ascending order.
The hire dates of all employees.
3. Which of the following SQL statements will display the name and a total of people
with the same last name?
215
4. Read the following SELECT statement. Choose the column or columns that MUST be
included in the GROUP BY clause.
SELECT region_id, COUNT(country_id)
FROM wf_countries
GROUP BY ?????
region_id, COUNT(country_id)
region_id,country_id
country_id
region_id (*)
6. Group functions cannot be used in subqueries because they contain too many rows.
True or False?
True
False (*)
216
True
False (*)
3. The DECODE and MAX functions can be used in PL/SQL statements. True or False?
True
False (*)
4. When PL/SQL converts data automatically from one data type to another, it is called
_______ conversion.
Explicit
Implicit (*)
TO_CHAR
Code containing implicit conversions typically runs faster than code containing explicit
conversions. (*)
Code containing implicit conversions may not work in the future if Oracle changes the
conversion rules.
Code containing implicit conversions is harder to read and understand
6. Using implicit conversions is good programming practice.
True
False (*)
Concatenation (*)
Exception
Exponential (*)
Arithmetic (*)
10. The TO_CHAR function is used for explicit data type conversions. True or False?
True (*)
False
217
END;
v_date := FROM_CHAR(v_char,'dd/mm/yy');
v_date := TO_DATE(v_char,'dd/mm/yy'); (*)
v_date := v_char;
12. Which of the following data type conversions can be done implicitly? (Choose two.)
DATE to NUMBER
NUMBER to VARCHAR2 (*)
NUMBER to PLS_INTEGER (*)
13. PL/SQL can implicitly convert a CHAR to a NUMBER, provided the CHAR contains
a numeric value, for example '123'. True or False?
True (*)
False
14. The LENGTH and ROUND functions can be used in PL/SQL statements. True or
False?
True (*)
False
218
Only the outer block
Both the inner and the outer block (*)
Only the inner block
Neither block
3,3
3,7
Null, 7 (*)
Null, 3
DECLARE
v_a NUMBER;
BEGIN
v_a := 27;
<<inner_block>>
BEGIN
v_a := 15;
END;
4. Examine the following code. At Line A, we want to assign a value of 25 to the outer
block's variable (V1). What must we do?
DECLARE
v_myvar NUMBER; -- This is V1
BEGIN
DECLARE
v_myvar NUMBER := 8;
219
BEGIN
-- Line A
END;
END; Mark for Review
(1) Points
At Line A, code:
v_myvar := 25;
It cannot be done because the outer block's v_myvar is out of scope at Line A.
Label the outer block and (at Line A) dot-prefix v_myvar with the block label. (*)
It cannot be done because the outer block's v_myvar is in scope but not visible at Line A.
5. What happens when an exception occurs in the executable section of a PL/SQL block
Oracle keeps trying to re-execute the statement which caused the exception.
The remaining statements in the executable section are not executed. Instead, Oracle looks for
an EXCEPTION section in the block. (*)
The remaining statements in the executable section of the block are executed.
The exception is always propagated to the calling environment.
6. Examine the following code. Line A causes an exception. What will be displayed
when the block is executed?
DECLARE
x NUMBER := 10;
y NUMBER;
BEGIN
x := 15;
y := 'Happy'; -- Line A
x := 20;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(x);
END;
10
20
15 (*)
Nothing is displayed
7. An inner block is nested within an outer block. An exception occurs within the inner
block, but the inner block does not have an EXCEPTION section. What happens?
The exception is propagated to the outer block and the remaining executable statements in the
outer block are skipped. (*)
The exception is propagated to the outer block and the remaining executable statements in the
outer block are executed.
220
Oracle automatically tries to re-execute the inner block.
The outer block is bypassed and the exception is always propagated to the calling
environment.
8. Examine the following nested blocks. Line B causes an exception. What will be
displayed when this code is executed?
DECLARE
var_1 NUMBER;
BEGIN
var_1 := 4;
DECLARE
var_2 NUMBER;
BEGIN
var_2 := 'Unhappy'; -- Line B
var_1 := 8;
END;
var_1 := 12;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_1);
END;
Unhappy
12
8
4 (*)
221
4. Examine the following code:
DECLARE
v_first_name varchar2 (30);
v_salary number (10);
BEGIN
SELECT first_name, salary
INTO v_first_name, v_salary
FROM employees
WHERE last_name = 'King';
END;
5. Which of the following makes PL/SQL code easier to read and maintain?
Place multiple statements on the same line.
Type everything in lowercase.
Use suitable comments in the code. (*)
Section 3
Quiz 1 Test: Quiz: Review of SQL DML
1. When inserting a row into a table, the VALUES clause must include a value for every
column of the table.
True or False (*)?
222
2. Is it possible to insert more than one row at a
time using an INSERT statement with a
VALUES clause?
No, you can only create one row at a time when using the VALUES clause. (*)
Yes, you can list as many rows as you want, just remember to separate the rows with commas.
No, there is no such thing as INSERT ... VALUES.
3. To modify an existing row in a table, you can use the ________ statement.
MODIFY
INSERT
ALTER
UPDATE (*)
223
5. What is wrong with the following statement?
DELETE from employees WHERE salary > (SELECT MAX(salary) FROM employees);
6. What is wrong with the following statement? MERGE INTO emps e USING new_emps ne
ON (e.employee_id = ne.employee_id) WHEN MATCHED THEN UPDATE SET ne.salary
= e.salary WHEN NOT MATCHED THEN INSERT VALUES (ne.employee_id,
ne.first_name, ne.last_name, .... ne.salary, ....);
The UPDATE clause must include the target table name: UPDATE emps SET ....
The INSERT clause must include a column list as well as a list of column values.
The SET clause is trying to update the source table from the target table. (*)
Nothing is wrong, the statement will execute correctly.
True
False (*)
224
Quiz 2 Test: Quiz: Retrieving Data in PL/SQL
225
UPDATE employees SET... (*)
226
2. Which one of these SQL statements can be
directly included in a PL/SQL executable block?
IF... THEN...;
227
SELECT * FROM DUAL;
SHOW USER;
3. Which of the following is NOT a valid guideline for retrieving data in PL/SQL?
Specify the same number of variables in the INTO clause as database columns in the
SELECT clause.
4. It is good programming practice to create identifiers having the same name as column
names. True or False?
True
False (*)
228
Yes (*)
6. When used in a PL/SQL block, which SQL statement must return exactly one row?
INSERT
UPDATE
SELECT (*)
MERGE
DELETE
7. Look at this PL/SQL block: DECLARE v_count NUMBER; BEGIN SELECT COUNT(*)
INTO v_count FROM employees WHERE salary > 50000; END; No employees earn more
than $50000. Which of the following statements are true? (Choose two).
229
The SELECT will return value 0 into V_COUNT. (*)
The SELECT will fail because it does NOT return exactly one row.
The block will fail because variable V_SALARY was not declared.
230
The block will fail because no results are displayed to the user.
The block will fail because the SELECT statement returns more than one row.
231
The block will fail because the SELECT is trying to read two columns into three PL/SQL
variables. (*)
The block will fail because V_LAST was declared before V_FIRST.
The block will execute successfully, and the V_SALARY variable will be set to NULL.
232
False (*)
233
INSERT and UPDATE only.
UPDATE and DELETE only.
INSERT, UPDATE and DELETE only.
INSERT, UPDATE, DELETE and MERGE. (*)
3. Employee_id 999 does not exist. What will happen when the following code is executed?
DECLARE employee_id employees.employee_id%TYPE := 999; BEGIN UPDATE
employees SET salary = salary * 1.1 WHERE employee_id = employee_id; END;
No rows are updated but the block completes successfully.
Every employee row is updated. (*)
An exception is raised because you cannot give a variable the same name as a table column.
An exception is raised because the UPDATE statement did not modify any rows.
4. There are three employees in department 90. What will be displayed when the following
code is executed? DECLARE v_open CHAR(3) := 'NO'; BEGIN UPDATE employees SET
job_id = 'ST_CLERK' WHERE department_id = 90; IF SQL%FOUND THEN v_open :=
'YES'; END IF; DBMS_OUTPUT.PUT_LINE(v_open || ' ' || SQL%ROWCOUNT); END;
NO 3
YES 1
YES 3 (*)
Nothing will be displayed. The block will fail because you cannot use implicit cursor
attributes directly in a call to DBMS_OUTPUT.PUT_LINE.
5. A PL/SQL block contains the following DML statement: UPDATE wf_countries SET
population = population * 1.1 WHERE country_id = 229; Which kind of cursor is used for
this statement?
An implicit cursor named "WF_COUNTRIES".
An implicit cursor named "SQL". (*)
An explicit cursor named "SQL".
An explicit cursor which must be declared and named by the PL/SQL programmer.
234
DML statements and SELECT statements which return a single row. (*)
COMMIT and ROLLBACK statements only.
cool cats
235
big birds and cool cats
aardvaarks and cool cats (*)
aardvaarks, big birds and cool cats
SECTIUNEA 8
Quiz 1
1. A stored function:
must have at least one IN parameter.
cannot be called in a SQL statement.
must return one and only one value. (*)
is called as a standalone executable statement.
Which variable is passed to the function and which variable is returned from the function?
236
DECLARE
v_mynum NUMBER(6,2);
v_mydate DATE;
BEGIN
... Line A
END;
6. Function GET_JOB accepts an employee id as input and returns that employee's job
id. Which of the following calls to the function will NOT work?
DBMS_OUTPUT.PUT_LINE(get_job(100));
IF get_job(100) = 'IT_PROG' THEN ...
get_job(100,v_job_id); (*)
v_job_id := get_job(100);
7. Function MYFUNC1 has been created, but has failed to compile because it contains
syntax errors. We now try to create procedure MYPROC1 which invokes this function. Which
of the following statements is true?
MYPROC1 will compile correctly, but will fail when it is executed.
MYPROC1 will compile and execute succesfully.
MYPROC1 will fail to compile because the function is invalid. (*)
MYPROC1 will compile and execute successfully, except that the call to MYFUNC1 will be
treated as a comment and ignored.
9. Procedure p1 has a single OUT parameter of type DATE. Function f1 returns a DATE.
What is the difference between p1 and f1?
p1 can be invoked from an anonymous block but f1 cannot
f1 can be used within a SQL statement but p1 cannot (*)
p1 can have as many IN parameters as needed but f1 cannot have more than two IN paramete
There is no difference because they both return a single value of the same datatype
237
RETURN (sal*12) + NVL(comm_pct,0)*12*sal;
END annual_comp;
B,E,F,D,A,C (*)
D,B,E,F,A,C
B,C,E,F,D,A
A,B,E,F,D,C
They can add business rules to the database and can be reused many times.
They can be used in a WHERE clause to filter data.
They can do the same job as built-in system functions such as UPPER and ROUND.
(*)
They can often be used inside SQL statements.
2. User-defined functions can extend the power of SQL statements where Oracle does
not provide ready-made functions such as UPPER and LOWER. True or False?
238
True (*) False
3. Which of the following is NOT a legal location for a function call in a SQL statement?
SELECT upd_dept(department_id)
FROM employees;
SELECT upd_dept(80)
FROM dual;
5. You want to create a function which can be used in a SQL statement. Which one of the
following can be coded within your function?
RETURN BOOLEAN
One or more IN parameters (*)
An OUT parameter
COMMIT;
239
RETURN(p_salary * 2);
END;
SELECT *
FROM employees
WHERE double_sal(salary) > 20000;
SELECT *
FROM employees
ORDER BY double_sal(salary) DESC;
UPDATE employees
SET salary = double_sal(salary);
It allows us to remind ourselves of the names of our tables, in case we have fogotten them.
3. User BOB is not a database administrator. BOB wants to see the names of all the
tables in his schema, as well as all the tables in other users' schemas which he has privileges
to use. Which Data Dictionary view would BOB query to do this?
USER_TABLES
ALL_TABLES (*)
DBA_TABLES
240
USER_TAB_COLUMNS
None of the above.
SELECT index_name
FROM user_indexes
WHERE index_name LIKE 'fn%';
fn_index
FN_INDEX
fn_index FN_INDEX
No output will be displayed (*)
6. Which of the following will display how many objects of each type are in a user's
schema? SELECT COUNT(*)
FROM user_objects;
DESCRIBE user_objects
GROUP BY object_type;
241
All of the above. (*)
None of the above.
8. You have forgotten the name of the Dictionary view USER_TABLES. Which of the
following statements is the best and quickest way to remind yourself?
242
An exception occurred
When call_ins_emp is executed, which rows will be inserted into the EMPLOYEES table?
99 only (*)
99 and 999
All three rows will be inserted
999 only
No rows will be inserted
3. The database administrator has granted the DROP ANY PROCEDURE privilege to
user KIM. This allows Kim to remove other users' procedures and functions from the
database. How would Kim now drop function GET_EMP, which is owned by user
MEHMET?
4. You need to remove procedure BADPROC from your schema. What is the correct
syntax to do this?
DELETE PROCEDURE badproc;
DROP PROGRAM badproc;
ALTER PROCEDURE badproc DISABLE;
DROP PROCEDURE badproc (*)
243
5. Which view would you query to see the detailed code of a procedure?
user_source (*)
user_procedures
user_objects
user_dependencies
user_errors
6. Which dictionary view will list all the PL/SQL subprograms in your schema?
user_source
user_procedures
user_objects (*)
user_dependencies
user_subprograms
1. User SVETLANA creates a view called EMP_VIEW that is based on a SELECT from
her EMPLOYEES table. Svetlana now wants user PHIL to be able to query the view. What is
the smallest set of object privileges that Svetlana must grant to Phil?
2. User COLLEEN owns an EMPLOYEES table and wants to allow user AYSE to create
indexes on the table. Which object privilege must Colleen grant to Ayse?
SELECT on EMPLOYEES
INDEX on EMPLOYEES (*)
ALTER on EMPLOYEES
CREATE on EMPLOYEES
None of the above
3. User FRED creates a procedure called DEL_DEPT using Definer's Rights, which
deletes a row from Fred's DEPARTMENTS table. What privilege(s) will user BOB need to be
able to execute Fred's procedure?
EXECUTE on DEL_DEPT (*)
EXECUTE on DEL_DEPT and DELETE on
DEPARTMENTS
EXECUTE on DEL_DEPT and DELETE on
FRED.DEPARTMENTS
DELETE on FRED.DEPARTMENTS
4. USERB creates a function called SEL_PROC (using Definer's Rights) which includes
the statement:
244
USERC needs to execute UserB's procedure. What privileges are needed for this to work
correctly? (Choose two.)
6. User TOM needs to grant both SELECT and INSERT privileges on both his
EMPLOYEES and DEPARTMENTS tables to both DICK and HARRY. What is the smallest
number of GRANT statements needed to do this?
1
2 (*)
3
4
8
The user who executes the procedure needs EXECUTE privilege on the procedure. (*)
The creator of the procedure needs SELECT privilege on EMPLOYEES.
The user who executes the procedure does not need any privileges.
The user who executes the procedure needs SELECT privilege on EMPLOYEES. (*)
2. Which of the following is the correct syntax to create a procedure using Invoker's
Rights?
CREATE PROCEDURE myproc IS
AUTHID CURRENT_USER
BEGIN ...
245
AUTHID CURRENT_USER IS
BEGIN ... (*)
3. User SALLY's schema contains a NEWEMP table. Sally uses Invoker's rights to
create procedure GET_NEWEMP which includes the line:
Sally also grants EXECUTE privilege on the procedure to CURLY, but no other privileges.
What will happen when Curly executes the procedure?
4. Users SYS (the DBA), TOM, DICK and HARRY each have an EMPLOYEES table in
their schemas. SYS creates a procedure DICK.SEL_EMP using Invoker's Rights which
contains the following code:
HARRY now executes the procedure. Which employees table will be queried?
SYS.EMPLOYEES
DICK.EMPLOYEES
HARRY.EMPLOYEES (*)
None of the above
Sectiunea 12
Test: Quiz 1: Understanding Dependencies
1. PL/SQL procedure A invokes procedure B, which in turn invokes procedure C, which
references table T. If table T is dropped, which of the following statements is true?
246
2. A procedure show_emps contains the following declaration:
CURSOR emp_curs IS SELECT last_name, salary FROM employees;
What will happen to the procedure if a new column is added to the employees table?
The procedure will still be valid and execute correctly because it does not reference the added
column.
The procedure will automatically be dropped and must be recreated.
The procedure will be marked invalid and must be recompiled before it can be reexecuted. (*)
Users' privileges to execute the procedure will automatically be revoked.
4. A single PL/SQL subprogram such as a procedure can be both a referenced object and
a dependent object. True or False?
True (*)
False
5. Which data dictionary view shows information about references and dependencies?
DEPTREE
USER_DEPENDENCIES (*)
USER_REFERENCES
USER_LOCAL_DEPENDENCIES
6. Which of the following statements will show whether procedure myproc is valid or
invalid?
SELECT status FROM USER_OBJECTS
WHERE object_type = 'PROCEDURE'
AND object_name = 'MYPROC'; (*)
247
The deptree_fill procedure (*)
8. User ALICE owns a procedure show_emps which references table employees. Which
of the following will generate information that shows this dependency?
BEGIN deptree_fill('TABLE','EMPLOYEES');
END;
BEGIN deptree_fill('PROCEDURE','ALICE','SHOW_EMPS');
END;
BEGIN deptree_fill('ALICE','TABLE','EMPLOYEES');
END;
BEGIN deptree_fill('TABLE','ALICE','EMPLOYEES');
END; (*)
BEGIN deptree_fill('ALICE','PROCEDURE','SHOW_EMPS');
END;
10. The IDEPTREE view shows dependencies by indenting the lines of output instead of
by using a NESTED_LEVEL column. True or False?
True (*)
False
11. Procedure get_depts has been marked invalid because one of the objects it references
has been altered. Which of the following statements are true? (Choose two.)
The procedure will be recompiled automatically the next time it is invoked. The recompilation
will always be successful.
The procedure will be recompiled automatically the next time it is invoked. The recompilation
may or may not be successful.(*)
The procedure can be recompiled manually by:
ALTER PROCEDURE get_depts COMPILE; (*)
248
The procedure can be recompiled manually by:
ALTER PROCEDURE get_depts RECOMPILE;
The procedure does not need to be recompiled.
Which of the following changes to the employees table will allow the procedure to be
recompiled successfully ? (Choose two.)
The table is dropped but a public table exists with the same name and structure.
(*)
The table is dropped.
A new column is added to the table. (*)
The table name is changed to newemps.
The first_name column is dropped from the table.
13. Which of the following will NOT help to minimize dependency failures? (Choose
two.)
SECTIUNEA 7
Test: Quiz 1: Creating Procedures
1. In an anonymous block, what is the keyword that starts the section where variables are
declared?
AS
IS
either IS or AS
DECLARE (*)
249
IS
either IS or AS (*)
DECLARE
7. Assuming you are USER1, what is the PL/SQL syntax for invoking a stored procedure
named "myproc" owned by a user named "USER2"?
EXECUTE USER2.myproc;
EXECUTE IMMEDIATE USER2.myproc;
call user2.myproc;
user2.myproc; (*)
8. You try to create a stored procedure called MYPROC1, but you make a number of
syntax errors. Where are your errors stored?
In MYPROC1.ERRORS
In a table named ERROR.LOG
In the dictionary view USER_ERRORS (*)
In a subprogram called ERRORS.MYPROC1
9. You have created a stored procedure called MYPROC2. Where is your detailed
procedure code stored?
In the dictionary view USER_PROCEDURES
In a table named LOG_ERRORS
In the dictionary view USER_SOURCE (*)
In the dictionary view USER_CODE
250
10. Which one of the following is a benefit of using stored subprograms?
Many users can share a single copy of the code in memory. (*)
They make backups of important data easier.
They automatically encrypt data.
They do not accept parameters.
11. You have created a procedure called MYPROC. Now you change some of the code
and want to recreate the procedure. What is the correct command to do this?
ALTER PROCEDURE myproc COMPILE;
CREATE OR REPLACE PROCEDURE myproc ... (*)
REPLACE PROCEDURE myproc ...
SAVE PROCEDURE AS myproc;
13. You tried to create a stored procedure named YOURPROC but you made a number of
errors. You now correct the errors and try to recreate the procedure by re-executing: CREATE
PROCEDURE yourproc ..... What will happen when you do this?
1. Which of the following 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 the name of a variable that is passed into or out of a procedure, while an
argument is the value of that variable (*)
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?
251
CREATE PROCEDURE (x NUMBER, y NUMBER)
myproc IS ...
CREATE PROCEDURE myproc IS (x NUMBER, y
NUMBER) ...
CREATE PROCEDURE IS myproc (x NUMBER, y
NUMBER) ナ
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. (*)
252
(p_param VARCHAR2)
IS BEGIN ...
DECLARE
v_param VARCHAR2(20) := 'Smith';
BEGIN
subproc(v_param);
END;
8. Which one of the following statements about formal and actual parameters is true?
10. You want to create a procedure which accepts a single parameter. The parameter is a
number with a maximum value of 9999.99. Which of the following is a valid declaration for
this parameter?
(v_num NUMBER(6,2))
(v_num NUMBER) (*)
(v_num)
(v_num NUMBER(4,2))
253
CONSTANT, VARIABLE, DEFAULT
COPY, NOCOPY, REF
2. If you don't specify a mode for a parameter, what is the default mode?
OUT
IN (*)
COPY
DEFAULT
R(ead)
3. Which of the following statements about IN OUT parameters is true? (Choose two.)
4. When creating a procedure, where in the code must the parameters be listed?
myproc('Smith',salary=>5000);
254
CONSTANT
R(ead)
W(rite)
Which one of the following calls to the procedure will NOT work?
myproc(80, 'Smith');
myproc(p_p1 => 80, 'Smith'); (*)
myproc(80, p_p2 => 'Smith');
myproc(p_p1 => 80, p_p2 => 'Smith');
255
256