Professional Documents
Culture Documents
Exception only
Executable only
Errors are handled in the Exception part of the PL/SQL block. True or False?
True (*)
False
Definition
Executable
Exception
Oracle jDeveloper
SQL*Plus
gSQL*Plus (*)
Which lines of code will correctly display the message "Hello World" ? (Choose two.)
DBMS_OUTPUT('Hello World');
DBMS_OUTPUT.PUT_LINE('Hello' || 'World');
True
False (*)
PL/SQL allows basic program logic and control flow to be combined with SQL statements.
(*)
PL/SQL and SQL can be used with many types of databases, including Oracle.
Which of the following statements is true?
conditional statements
constants
variables
nonprocedural constructs (*)
Exception handling code tells your program what to do when an error is encountered.
PL/SQL differs from C and Java in which of the following ways? (Choose two.)
Procedural constructs give you better control of your SQL statements and their execution. True or
False?
True (*)
False
Using Oracle Application Express, you can create Web applications that include PL/SQL. True or
False?
TRUE (*)
FALSE
1. In which three ways does PL/SQL extend the SQL programming language? (1) Points
(Choose all correct answers)
By adding procedural constructs. (*)
By adding compound constructs.
By adding iterative control. (*)
By adding conditional control. (*)
1. You can create a Web site application written entirely in PL/SQL. True or False?
♦True (*)
♦False
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.
5. When multiple SQL statements are combined into PL/SQL blocks, performance
improves. True or False?
♦True (*)
♦False
6. 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. (*)
2. 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. (*)
3. Procedural constructs give you better control of your SQL statements and their
execution. True or False?
♦True (*)
♦False
4. 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.
6. You can create a Web site application written entirely in PL/SQL. True or False?
♦True (*)
♦False
10. Which lines of code will correctly display the message “Hello World” ? (Choose two.)
DBMS_OUTPUT(‘Hello World’);
DBMS_OUTPUT.PUT_LINE(‘Hello World’); (*)
DBMS_OUTPUT.PUT_LINE(‘Hello’ || ‘World’);
DBMS_OUTPUT.PUT_LINE(‘Hello’ || ‘ ‘ || ‘World’); (*)
1.04. Review of SQL Select Statements
1. Examine the following statement:
SELECT country_name, population, population*.01
FROM wf_countries;
How would you modify this statement to display “Country”, “Population”, and “Expected
Growth” as the column headings?
2. Which statement would select salaries that are greater than or equal to 2500 and less
than or equal to 3500? Choose two correct answers.
4. Which statement would display the departments in the EMPLOYEES table without
displaying any duplicates?
5. If you want to SELECT all the columns of data in a table, you use which of the following
symbols?
♦&
♦%
♦$
♦* (*)
6. Which of the following statements displays the population of the Republic of Benin
(country_id 229) after a 3 percent growth in its population?
8. When using the LIKE operator, the “%” and “_” symbols can be used to do a pattern-
matching, wild card search. True or False?
♦True (*)
♦False
♦Incorrect.
9. 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?
10. What can you use to change the column heading of calculated values in a SQL
statement?
♦Multiplication operator
♦Column alias (*)
♦Concatenation operator
♦The DISTINCT keyword
11. Which of the following statements lists each employee’s employee_id, salary, and
salary plus a 20 percent bonus?
12. 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?
13. 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?
♦TodayisThursday!
♦Today isThursday! (*)
♦today is thursday!
♦Today is Thursday!
♦Incorrect
2. The following SQL statement will display the value: 456. True or False?
SELECT TRUNC(ROUND(456.98))
FROM dual;
♦True
♦False (*)
3. Which statement returns a user password combining the ID of an employee and the
first 4 characters of their last name?
♦True
♦False (*)
♦TO_DATE (*)
♦ROUND
♦MOD
♦TRUNC
6. 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 (*)
♦Programming
♦PROGRAMMING (*)
♦Database
♦DATABASE
8. 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);
9. Which function compares two expressions?
♦NVL
♦NULLIF (*)
♦NVL2
♦NULL
10. 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;
11. What function would you use to return the highest date in a month?
♦FINAL_DAY
♦END_DAY
♦HIGHEST_DAY
♦LAST_DAY (*)
12. Which query would return a whole number if today’s date is 26-MAY-04?
PL/SQL can be used not only with an Oracle database, but also with any kind of
relationaldatabase.
False*
1. SQL is a common access language for many types of databases, including Oracle. True
or False? (1) Points
True (*)
False
2. The P in PL/SQL stands for: (1) Points
Processing
Procedural (*)
Primary
Proprietary
3. Which of the following statements about PL/SQL and SQL is true? (1) Points
PL/SQL and SQL are both ANSI-compliant.
PL/SQL and SQL can be used with many types of databases, including Oracle.
PL/SQL and SQL are both Oracle proprietary programming languages.
PL/SQL allows basic program logic and control flow to be combined with SQL
statements. (*)
4. Every PL/SQL anonymous block must start with the keyword DECLARE. True or False?
(1) Points
True
False (*)
5. Which of the following tools can NOT be used to develop and test PL/SQL code? (1)
Points
Oracle Jdeveloper
Oracle Application Express
Oracle JSQL (*)
Oracle iSQL*Plus
8. In which part of the PL/SQL block are declarations of variables defined? (1) Points
Executable
Exception
Declarative (*)
Definition
12. PL/SQL can be used not only with an Oracle database, but also with any kind of
relational database. True or False? (1) Points
True
False (*)
Section 2
13. A collection is a composite data type. True or False? (1) Points
True (*)
False
14. Type of a variable determines the range of values the variable can have and the set of
operations that are defined for values of the type. (1) Points
True (*)
False
15. Which of these are PL/SQL data types? (Choose three.) (1) Points (Choose all correct
answers)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
16. Examine the following code:
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
After line 4, what is the value of x?
(1) Points
'300'
300 (*)
NULL
Incorrect. Refer to Section 2 Lesson 5.
17. The implicit data type conversion at Point A may not work correctly. Why not?
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-04'; -- Point A
END;
(1) Points
There are only 28 days in February
Oracle cannot implicitly convert a character string to a date, even if the string contains a
valid date value *
If the database language is not English, 'Feb' has no meaning.
V_MYDATE has been entered in uppercase
18. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of: (1) Points
Implicit conversion functions
Explicit conversion functions (*)
Character functions
Operators
19. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
(1) Points
81
49
14 (*)
18
20. PL/SQL can convert a VARCHAR2 value containing alphabetic characters to a NUMBER
value. True or False? (1) Points
True
False (*)
21. What is wrong with this assignment statement?
myvar := 'To be or not to be';
'That is the question';
(1) Points
An assignment statement must be a single line of code
Nothing is wrong, the statement is fine
An assignment statement must have a single semicolon at the end (*)
"myvar" is not a valid name for a variable
Character literals should not be enclosed in quotes
22. Which of the following are valid assignment statements? (Choose two.) (1) Points
(Choose all correct answers)
v_string = 'Hello';
v_string := Hello;
v_number := 17 + 34; (*)
v_string := 'Hello'; (*)
v_date := 28-DEC-06;
23. If today's date is 14th June 2007, which statement will correctly convert today's date
to the value: June 14, 2007 ? (1) Points
TO_CHAR(sysdate)
TO_DATE(sysdate)
TO_DATE(sysdate,'Month DD, YYYY')
TO_CHAR(sysdate, 'Month DD, YYYY') (*)
24. Which of the following is an example of using a case convention for good
programming practice? (1) Points
Assign variables by using functions.
Declare variables in the DECLARE section.
Declare data types in uppercase. (*)
Include an exception handler in every PL/SQL block.
Incorrect. Refer to Section 2 Lesson 7.
25. To comment a single line of code, use two dashes after the comment. True or False?
(1) Points
True
False (*)
26. Using standards for naming conventions is recommended. True or False? (1) Points
True (*)
False
27. Which statements about lexical units are true? (Choose two.) (1) Points (Choose all
correct answers)
They are named objects stored in the database
They are the building blocks of every PL/SQL program (*)
They are optional but can make a PL/SQL block execute faster
They are sequences of characters including letters, digits, tabs, returns and symbols (*)
28. Which of the following are valid identifiers? (Choose two.) (1) Points (Choose all
correct answers)
Full Name
students_street_address (*)
v_code (*)
#hours
completion_%
29. Which of the following are PL/SQL lexical units? (Choose two.) (1) Points (Choose all
correct answers)
Identifiers (*)
Table Columns
Reserved Words (*)
Anonymous Blocks
SQL Workshop
30. Evaluate the following declaration. Determine whether or not it is legal.
DECLARE
maxsalary NUMBER(7) = 5000;
(1) Points
Correct.
Not correct. (*)
31. Assignment statements can continue over several lines in PL/SQL. True or False? (1)
Points
True (*)
False
32. When a variable is defined using the NOT NULL keywords, the variable must contain a
value. True or False? (1) Points
True (*)
False
33. Variables can be assigned a value in both the Executable and Declaration sections of a
PL/SQL program. True or False? (1) Points
True (*)
False
34. 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;
(1) Points
Susan
Chang (*)
ChangChang
SusanChang
The code will fail with an error
35. An exception occurs within the inner block of two nested blocks. The inner block does
not have an EXCEPTION section. What always happens? (1) Points
Both blocks fail and an error message is displayed by the calling environment
The exception is propagated to the outer block (*)
Oracle automatically tries to re-execute the inner block
The user's database session is automatically disconnected
36. What will be displayed when the following code is executed?
DECLARE
varA NUMBER := 12;
BEGIN
DECLARE
varB NUMBER := 8;
BEGIN
varA := varA + varB;
END;
DBMS_OUTPUT.PUT_LINE(varB);
END;
(1) Points
8
12
Nothing, the block will fail with an error (*)
20
VarB
37. 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;
(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
38. What will be displayed when the following block is executed?
<<outer>>
DECLARE
v_myvar VARCHAR2(10) := 'Hello' ;
BEGIN
<<inner>> DECLARE
v_myvar VARCHAR2(10) := 'World';
BEGIN
v_myvar := v_myvar || ' ' || outer.v_myvar;
END;
DBMS_OUTPUT.PUT_LINE(inner.v_myvar);
END;
(1) Points
HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the outer block. (*)
39. Which of the following can be assigned to a Boolean variable?
1. Null
2. False
3. True
4. 0
(1) Points
2 and 3
2, 3 and 4
1, 2 and 3 (*)
1, 2, 3 and 4
40. If you are using the %TYPE attribute, you can avoid hard coding the: (1) Points
Data type (*)
Table name
Column name
Constraint
41. A variable must have a value if NOT NULL is specified. True or False? (1) Points
True (*)
False
Section 3
42. The following anonymous block of code is run:
BEGIN
INSERT INTO countries (id, name)
VALUES ('XA', 'Xanadu');
INSERT INTO countries (id, name)
VALUES ('NV','Neverland');
COMMIT;
COMMIT;
ROLLBACK;
END;
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;
45. Which one of these SQL statements can be directly included in a PL/SQL executable
block? (1) Points
DELETE FROM employees
WHERE department_id=60; (*)
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;
47. 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;
(1) Points
All rows whose SALARY column value is greater than 12000.
All rows in the table.
No rows. (*)
All rows whose SALARY column value is equal to 12000.
48. Which is the correct way to erase one row from a table? (1) Points
REMOVE employee_id=100
FROM employees;
DROP TABLE employees
WHERE employee_id=100;
TRUNCATE employees
WHERE employee_id=100;
What is the value of SQL%ISOPEN immediately after the SELECT statement is executed?
(1) Points
True
False (*)
Null
Error. That attribute does not apply for implicit cursors.
50. Which SQL statement can NOT use an implicit cursor? (1) Points
A DELETE statement
An UPDATE statement
A SELECT statement that returns multiple rows (*)
A SELECT statement that returns one row
True
False (*)
2. PL/SQL extends SQL by including all of the following except: (1) Points
variables
conditional statements
reusable program units
constants
nonprocedural constructs (*)
3. Which of the following statements about PL/SQL and SQL is true? (1) Points
PL/SQL and SQL are both ANSI-compliant.
PL/SQL and SQL can be used with many types of databases, including Oracle.
PL/SQL and SQL are both Oracle proprietary programming languages.
PL/SQL allows basic program logic and control flow to be combined with SQL
statements. (*)
4. Using Oracle Application Express, you can create Web applications that include PL/SQL.
True or False? (1) Points
True (*)
False
5. The fact that PL/SQL is portable is a good thing because: (1) Points
Exceptions can be ported to different operating systems
Blocks can be sent to the operating system.
PL/SQL code can be developed on one platform and deployed on another (*)
PL/SQL code can be run on any operating system without a database
6. Which of the following can you use PL/SQL to do? (1) Points
Update data (DML)
Develop Web applications using the Web Application Toolkit
Manage database security
Create customized reports
All of the above (*)
7. Which of the following tools can NOT be used to develop and test PL/SQL code? (1)
Points
Oracle Jdeveloper
Oracle Application Express
Oracle JSQL (*)
Oracle iSQL*Plus
8. What kind of block is defined by the following PL/SQL code?
BEGIN
DBMS_OUTPUT.PUT_LINE('My first quiz');
END;
(1) Points
procedure
subroutine
function
anonymous (*)
9. Given below are the parts of a PL/SQL block:
1. END;
2. EXCEPTION
3. DECLARE
4. BEGIN
10. Which lines of code will correctly display the message "The cat sat on the mat"?
(Choose two.) (1) Points (Choose all correct answers)
DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)
DBMS_OUTPUT.PUT_LINE(The cat sat on the mat);
DBMS_OUTPUT.PUT_LINE('The cat' || 'sat on the mat');
DBMS_OUTPUT.PUT_LINE('The cat sat ' || 'on the mat'); (*)
11. What is the purpose of using DBMS_OUTPUT.PUT_LINE in a PL/SQL block? (1) Points
To perform conditional tests
To allow a set of statements to be executed repeatedly
To display results to check if our code is working correctly (*)
To store new rows in the database
12. Errors are handled in the Exception part of the PL/SQL block. True or False? (1) Points
True (*)
False
13. Type of a variable determines the range of values the variable can have and the set of
operations that are defined for values of the type. (1) Points
True (*)
False
14. Which of these are PL/SQL data types? (Choose three.) (1) Points (Choose all correct
answers)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
15. A movie is an example of which category of data type? (1) Points
Scalar
Composite
Reference
LOB (*)
16. Which of the following are valid identifiers? (Choose two.) (1) Points (Choose all
correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
17. Which of the following are PL/SQL lexical units? (Choose two.) (1) Points (Choose all
correct answers)
Identifiers (*)
Table Columns
Reserved Words (*)
Anonymous Blocks
SQL Workshop
18. Delimiters are _____ that have special meaning to the Oracle database. (1) Points
identifiers
variables
symbols (*)
19. When nested blocks are used, which blocks can or must be labeled? (1) Points
The inner block must be labeled, the outer block can be labeled.
Both blocks must be labeled
Nested blocks cannot be labeled
The outer block must be labeled if it is to be referred to in the inner block. (*)
20. What will be displayed when the following block is executed?
<<outer>>
DECLARE
v_myvar VARCHAR2(10) := 'Hello' ;
BEGIN
<<inner>> DECLARE
v_myvar VARCHAR2(10) := 'World';
BEGIN
v_myvar := v_myvar || ' ' || outer.v_myvar;
END;
DBMS_OUTPUT.PUT_LINE(inner.v_myvar);
END;
(1) Points
HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the outer block. (*)
21. 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;
(1) Points
My
My name (*)
My name is
My name is Zeynep
22. 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;
(1) Points
Susan
Chang (*)
ChangChang
SusanChang
The code will fail with an error
23. Examine the following code. Line A causes an exception. What will be displayed when
the block is executed?
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
DBMS_OUTPUT.PUT_LINE(var_a);
END;
(1) Points
12 (*)
24
6
Nothing will be displayed
24. To comment a single line of code, use two dashes after the comment. True or False?
(1) Points
True
False (*)
25. Which of the following will help to make code easier to read? (1) Points
Naming variables.
Using %Type.
Including comments in the code. (*)
26. Using standards for naming conventions is recommended. True or False? (1) Points
True (*)
False
27. If today's date is 14th June 2007, which statement will correctly convert today's date
to the value: June 14, 2007 ? (1) Points
TO_CHAR(sysdate)
TO_DATE(sysdate)
TO_DATE(sysdate,'Month DD, YYYY')
TO_CHAR(sysdate, 'Month DD, YYYY') (*)
28. 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;
(1) Points
True (*)
False
29. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
(1) Points
81
49
14 (*)
18
30. Single row character functions are valid SQL functions in PL/SQL. True or False? (1)
Points
True (*)
False
31. The implicit data type conversion at Point A may not work correctly. Why not?
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-04'; -- Point A
END;
(1) Points
There are only 28 days in February
Oracle cannot implicitly convert a character string to a date, even if the string contains a
valid date value
If the database language is not English, 'Feb' has no meaning. (*)
V_MYDATE has been entered in uppercase
33. When you use a function to convert data types in a PL/SQL program, it is called
______ conversion. (1) Points
Explicit (*)
Implicit
TO_CHAR
34. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of: (1) Points
Implicit conversion functions
Explicit conversion functions (*)
Character functions
Operators
35. Assignment statements can continue over several lines in PL/SQL. True or False? (1)
Points
True (*)
False
36. When a variable is defined using the NOT NULL keywords, the variable must contain a
value. True or False? (1) Points
True (*)
False
37. Evaluate the following declaration. Determine whether or not it is legal.
DECLARE
maxsalary NUMBER(7) = 5000;
(1) Points
Correct.
Not correct. (*)
38. Variables can be used in the following ways in a PL/SQL block. (Choose two.) (1)
Points
(Choose all correct answers)
To store data values. (*)
To rename tables and columns.
To refer to a single data value several times. (*)
To comment code.
39. A variable must have a value if NOT NULL is specified. True or False? (1) Points
True (*)
False
40. You need to declare a variable to hold a value which has been read from the SALARY
column of the EMPLOYEES table. Which of the following is an advantage of declaring the
variable as: employees.salary%TYPE ? (1) Points
It is shorter than coding NUMBER(8,2)
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
It executes much faster than using NUMBER(8,2)
It allows the software to perform implicit data type conversions.
Java
PL/SQL
SQL*
MySQL*
C++
Section 1
1. The fact that PL/SQL is portable is a good thing because: (1) Points
Exceptions can be ported to different operating systems
Blocks can be sent to the operating system.
PL/SQL code can be developed on one platform and deployed on another (*)
PL/SQL code can be run on any operating system without a database
2. Which of the following statements about exception handling in PL/SQL is false? (1)
Points
You can prepare for database exceptions by creating exception handlers.
You can prepare for application exceptions by creating exception handlers.
Exception handling code tells your program what to do when an error is encountered.
Exception handling code can be grouped together in a PL/SQL block.
None of the above (*)
3. PL/SQL can be used not only with an Oracle database, but also with any kind of
relational database. True or False? (1) Points
True
False (*)
4. What kind of block is defined by the following PL/SQL code?
BEGIN
DBMS_OUTPUT.PUT_LINE('My first quiz');
END;
(1) Points
procedure
subroutine
function
anonymous (*)
5. In which part of the PL/SQL block are declarations of variables defined? (1) Points
Executable
Exception
Declarative (*)
Definition
6. Which lines of code will correctly display the message "The cat sat on the mat"?
(Choose two.) (1) Points (Choose all correct answers)
DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)
DBMS_OUTPUT.PUT_LINE(The cat sat on the mat);
DBMS_OUTPUT.PUT_LINE('The cat' || 'sat on the mat');
DBMS_OUTPUT.PUT_LINE('The cat sat ' || 'on the mat'); (*)
7. Which component of Oracle Application Express is used to enter and run SQL
statements and PL/SQL blocks? (1) Points
Application Builder
SQL Workshop (*)
Utilities
Object Browser
8. Which keywords must be included in every PL/SQL block? (Choose two.) (1) Points
(Choose all correct answers)
DECLARE
END; (*)
EXCEPTION
BEGIN (*)
DBMS_OUTPUT.PUT_LINE
9. Which statements are optional in a PL/SQL block? (Choose two.) (1) Points (Choose all
correct answers)
DECLARE (*)
BEGIN
EXCEPTION (*)
END;
10. PL/SQL extends SQL by including all of the following except: (1) Points
variables
conditional statements
reusable program units
constants
nonprocedural constructs (*)
11. SQL is a common access language for many types of databases, including Oracle. True
or False? (1) Points
True (*)
False
Section 2
13. Valid identifiers begin with a (1) Points
Number
Letter (*)
Special character
14. Delimiters are _____ that have special meaning to the Oracle database. (1) Points
identifiers
variables
symbols (*)
15. Which of the following are valid identifiers? (Choose two.) (1) Points (Choose all
correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
16. 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;
(1) Points
Susan
Chang (*)
ChangChang
SusanChang
The code will fail with an error
17. When nested blocks are used, which blocks can or must be labeled? (1) Points
The inner block must be labeled, the outer block can be labeled.
Both blocks must be labeled
Nested blocks cannot be labeled
The outer block must be labeled if it is to be referred to in the inner block. (*)
18. When an exception occurs within a PL/SQL block, the remaining statements in the
executable section of the block are skipped. True or False? (1) Points
True (*)
False
19. 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;
(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
20. Examine the following code. Line A causes an exception. What will be displayed when
the block is executed?
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
DBMS_OUTPUT.PUT_LINE(var_a);
END;
(1) Points
12 (*)
24
6
Nothing will be displayed
Section 2
21. Which of the following declarations is invalid? (1) Points
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
v_pages CONSTANT NUMBER; (*)
v_start_date DATE := sysdate+1;
22. If you are using the %TYPE attribute, you can avoid hard coding the: (1) Points
Data type (*)
Table name
Column name
Constraint
23. A variable must have a value if NOT NULL is specified. True or False? (1) Points
True (*)
False
24. Which of the following will help to make code easier to read? (1) Points
Naming variables.
Using %Type.
Including comments in the code. (*)
25. Which of these are examples of good programming practice? (Choose three.) (1)
Points
(Choose all correct answers)
Declare two variables on each line of code.
Use a NOT NULL constraint when a variable must have a value (*)
Use a clear and consistent naming convention for variables. (*)
Declare variables with the same names as table columns.
Do not rely on implicit data type conversions. (*)
26. To comment a single line of code, use two dashes after the comment. True or False?
(1) Points
True
False (*)
27. 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; ...
(1) Points
Scalar
Composite (*)
LOB
28. A collection is a composite data type. True or False? (1) Points
True (*)
False
29. ______ are meant to store large amounts of data. (1) Points
Variables
Scalar data types
LOBs (*)
30. Variables can be used in the following ways in a PL/SQL block. (Choose two.) (1)
Points (Choose all correct answers)
To store data values. (*)
To rename tables and columns.
To refer to a single data value several times. (*)
To comment code.
Section 2
31. Assignment statements can continue over several lines in PL/SQL. True or False? (1)
Points
True (*)
False
39. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of: (1) Points
Implicit conversion functions
Explicit conversion functions (*)
Character functions
Operators
40. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
(1) Points
81
49
14 (*)
18
Section 2
41. When you use a function to convert data types in a PL/SQL program, it is called
______ conversion. (1) Points
Explicit (*)
Implicit
TO_CHAR
Section 3
42. Which of the following best describes a database transaction? (1) Points
All the DML statements in a single PL/SQL block
A related set of SQL DML statements which must be executed either completely or not
at all (*)
A single SQL statement that updates multiple rows of a table
A SELECT statement based on a join of two or more database tables
43. The following anonymous block of code is run:
BEGIN
INSERT INTO countries (id, name)
VALUES ('XA', 'Xanadu');
SAVEPOINT XA;
INSERT INTO countries (id, name)
VALUES ('NV','Neverland');
COMMIT;
ROLLBACK TO XA;
END;
What happens when the block of code finishes?
(1) Points
No data is inserted and no errors occur.
No data is inserted and an error occurs
Two rows are inserted and no errors occur.
Two rows are inserted and an error occurs. (*)
44. Which one of these SQL statements can be directly included in a PL/SQL executable
block? (1) Points
SELECT last_name FROM employees
WHERE employee_id=100;
DESCRIBE employees;
UPDATE employees
SET last_name='Smith'; (*)
SELECT salary
FROM employees
WHERE employee_id=100
INTO v_salary;
46. 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;
(1) Points
True
False (*)
47. Which of the following is NOT a good guideline for retrieving data in PL/SQL? (1)
Points
Declare the receiving variables using %TYPE
The WHERE clause is optional in nearly all cases. (*)
Specify the same number of variables in the INTO clause as database columns in the
SELECT clause.
THE SELECT statement should fetch exactly one row.
48. A PL/SQL block includes the following statement:
SELECT last_name INTO v_last_name
FROM employees
WHERE employee_id=100;
What is the value of SQL%ISOPEN immediately after the SELECT statement is executed?
(1) Points
True
False (*)
Null
Error. That attribute does not apply for implicit cursors.
49. There are no employees in Department 77. What will happen when the following
block is executed?
BEGIN
DELETE FROM employees
WHERE department_id=77;
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
END;
(1) Points
A NO_DATA_FOUND exception is raised.
A NULL is displayed.
A zero (0) is displayed. (*)
An exception is raised because the block does not contain a COMMIT statement.
50. Which SQL statement can NOT use an implicit cursor? (1) Points
A DELETE statement
An UPDATE statement
A SELECT statement that returns multiple rows (*)
A SELECT statement that returns one row
True
False (*)
Null
Error. That attribute does not apply for implicit cursors.
2. Assume there are 5 employees in Department 10. What happens when the
following statement is executed?
UPDATE employees
SET salary=salary*1.1;
(1) Points
3. You declare an implicit cursor in the DECLARE section of a PL/SQL block. True
or False? (1) Points
True
False (*)
DECLARE
v_result employees.salary%TYPE;
BEGIN
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; (*)
5. 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;
(1) Points
True
False (*)
7. Which of the following is NOT a good guideline for retrieving data in PL/SQL? (1)
Points
Declare the receiving variables using %TYPE
The WHERE clause is optional in nearly all cases. (*)
Specify the same number of variables in the INTO clause as database columns in the
SELECT clause.
THE SELECT statement should fetch exactly one row.
8. Which one of these SQL statements can be directly included in a PL/SQL executable
block?
(1) Points
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;
(1) Points
10. Single row character functions are valid SQL functions in PL/SQL. True or False? (1)
Points
True (*)
False
12. Which of the following are valid assignment statements? (Choose two.) (1) Points
(Choose all correct answers)
v_string = 'Hello';
v_string := Hello;
v_number := 17 + 34; (*)
v_string := 'Hello'; (*)
v_date := 28-DEC-06;
13. The DECODE function is available in PL/SQL procedural statements. True or False?
(1) Points
True
False (*)
14. When you use a function to convert data types in a PL/SQL program, it is called
______ conversion. (1) Points
Explicit (*)
Implicit
TO_CHAR
15. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of: (1) Points
Implicit conversion functions
Explicit conversion functions (*)
Character functions
Operators
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;
(1) Points
True (*)
False
18. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
(1) Points
81
49
14 (*)
18
19. Reserved words can be used as identifiers. True or False? (1) Points
True
False (*)
20. Which of the following are PL/SQL lexical units? (Choose two.) (1) Points (Choose
all correct answers)
Identifiers (*)
Table Columns
Reserved Words (*)
Anonymous Blocks
SQL Workshop
21. Which of the following are valid identifiers? (Choose two.) (1) Points (Choose all
correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
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
<<inner_block>>
DECLARE
23. An exception occurs within the inner block of two nested blocks. The inner block
does not have an EXCEPTION section. What always happens? (1) Points
Both blocks fail and an error message is displayed by the calling environment
The exception is propagated to the outer block (*)
Oracle automatically tries to re-execute the inner block
The user's database session is automatically disconnected
END;
(1) Points
8
12
Nothing, the block will fail with an error (*)
20
VarB
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;
(1) Points
My
My name (*)
My name is
My name is Zeynep
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
Susan
Chang (*)
ChangChang
SusanChang
The code will fail with an error
27. Assignment statements can continue over several lines in PL/SQL. True or False?
(1) Points
True (*)
False
28. Variables can be assigned a value in both the Executable and Declaration sections
of a PL/SQL program. True or False? (1) Points
True (*)
False
29. Variables can be used in the following ways in a PL/SQL block. (Choose two.) (1)
Points
(Choose all correct answers)
To store data values. (*)
To rename tables and columns.
To refer to a single data value several times. (*)
To comment code. To comment code.
30. When a variable is defined using the NOT NULL keywords, the variable must
contain a value. True or False? (1) Points
True (*)
False
31. Identify which of the following assignment statements are valid. (Choose three.)
(1) Points (Choose all correct answers)
v_last_name := Chandra;
v_blackout_date := '31-DEC-2006'; (*)
v_population := 333444; (*)
v_music_type := 'ROCK'; (*)
32. Which of these are PL/SQL data types? (Choose three.) (1) Points (Choose all
correct answers)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
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; ...
(1) Points
Scalar
Composite (*)
LOB
34. ______ are meant to store large amounts of data. (1) Points
Variables
Scalar data types
LOBs (*)
35. Every PL/SQL anonymous block must start with the keyword DECLARE. True or
False? (1) Points
True
False (*)
36. Which keywords must be included in every PL/SQL block? (Choose two.) (1) Points
(Choose all correct answers)
DECLARE
END; (*)
EXCEPTION
BEGIN (*)
DBMS_OUTPUT.PUT_LINE
37. Errors are handled in the Exception part of the PL/SQL block. True or False? (1)
Points
True (*)
False
38. Which PL/SQL block type must return a value? (1) Points
Anonymous
Function (*)
Procedure
2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
40. Which lines of code will correctly display the message "The cat sat on the mat"?
(Choose two.) (1) Points
(Choose all correct answers)
DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)
DBMS_OUTPUT.PUT_LINE(The cat sat on the mat);
DBMS_OUTPUT.PUT_LINE('The cat' || 'sat on the mat');
DBMS_OUTPUT.PUT_LINE('The cat sat ' || 'on the mat'); (*)
42. Which of the following tools can NOT be used to develop and test PL/SQL code? (1)
Points
Oracle Jdeveloper
Oracle Application Express
Oracle JSQL (*)
Oracle iSQL*Plus
44. 1. Null
2. False
3. True
4. 0
2 and 3
2, 3 and 4
1, 2 and 3 (*)
1, 2, 3 and 4
45. A variable must have a value if NOT NULL is specified. True or False? (1) Points
True (*)
False
END;
You have nothing new; the last ROLLBACK undid the INSERTs.
You have the rows added twice; there are four new rows.
You have the two new rows added. (*)
You get an error; you cannot COMMIT twice in a row.
47. Which of the following best describes a database transaction? (1) Points
All the DML statements in a single PL/SQL block
A related set of SQL DML statements which must be executed either completely or not
at all (*)
A single SQL statement that updates multiple rows of a table
A SELECT statement based on a join of two or more database tables
48. Which of the following statements about PL/SQL and SQL is true? (1) Points
PL/SQL and SQL are both ANSI-compliant.
PL/SQL and SQL can be used with many types of databases, including Oracle.
PL/SQL and SQL are both Oracle proprietary programming languages.
PL/SQL allows basic program logic and control flow to be combined with SQL
statements. (*)
Comparing PL/SQL with other languages such as C and Java, which of the following statements is
true?
PL/SQL is easier to learn and does not require an Oracle database or tool
Section 1
DECLARE
name,dept VARCHAR2(14);
(1) Points
legal
illegal (*)
Which of the following correctly assigns the value 50 to V_RESULT? (1) Points
v_result := v_number * 5;
v_result := 100 / 2;
v_result := ROUND(49.77);
3. After they are declared, variables can be used only once in an application. True or False? (1)
Points
True
False (*)
True (*)
False
legal (*)
illegal
6. Which of the following are required when declaring a variable? (Choose two.) (1) Points
(Choose all correct answers)
Identifier name (*)
CONSTANT
NOT NULL
True (*)
False
Which of the following statements correctly assigns the date variable v_today to the value
returned by the format_todays_date function?
(1) Points
v_today := format_todays_date(v_today);
False*
True*
A datatype may specify a valid range of values.
True*
Section 1
1. Which of the folowing are scalar data types? (Choose three.) (1) Points (Choose all correct
answers)
Array
Character (*)
Table
Date (*)
Boolean (*)
CLOB
VARCHAR2
RECORD (*)
DATE
3. What are the data types of the variables in the following declaration?
DECLARE
fname VARCHAR2(20);
BEGIN
...
(1) Points
Scalar (*)
Composite
LOB
4. A datatype may specify a valid range of values. True or False? (1) Points
True (*)
False
Multi
Large
Single (*)
6. A datatype specifies and restricts the possible data values that can be assigned to a variable.
True or False? (1) Points
True (*)
False
7. Which of the following are PL/SQL data types? (Choose three.) (1) Points (Choose all correct
answers)
Lexical
Scalar (*)
Delimiter
Composite (*)
Section 1
1. If you use the %TYPE attribute, you can avoid hard-coding the column name. True or False?
(1) Points
True
False (*)
2. Code is easier to read if you declare one identifier per line. True or False? (1) Points
True (*)
False
3. Which of the following is NOT a good guideline for declaring variables? (1) Points
4. Which of the following variable declarations does NOT use a number data type? (1) Points
v_count PLS_INTEGER := 0;
v_median_age NUMBER(6,2);
v_count BINARY_INTEGER;
5. When declared using %TYPE, a variable will inherit ____ from the column on which it is based.
(1) Points
The name of the column
VARCHAR2
BOOLEAN (*)
CHAR
LONG
♦v_result := v_number * 5;
♦v_result := 100 / 2;
♦v_result := ROUND(49.77);
2. After they are declared, variables can be used only once in an application. True or False?
♦True
♦False (*)
♦True (*)
♦False
Which of the following statements correctly assigns the date variable v_today to the value
returned by the format_todays_date function?
♦v_today := format_todays_date(v_today);
5. Which of the following are required when declaring a variable? (Choose two.)
♦CONSTANT
♦NOT NULL
DECLARE
name,dept VARCHAR2(14);
♦legal
♦illegal (*)
test NUMBER(5);
♦legal (*)
♦illegal
2.02. Recognizing PL/SQL lexical units
♦? ?
♦*/ / *
♦:: ::
♦/* */ (*)
♦A type of variable
♦True (*)
♦False
♦Data types
♦PL/SQL blocks
♦Identifiers (*)
♦Literals (*)
♦Parentheses: ()
6. Which of the following is a valid naming convention for an identifier? (Choose two.)
♦Lexical
♦Scalar (*)
♦Delimiter
♦Composite (*)
2. What are the data types of the variables in the following declaration?
DECLARE
fname VARCHAR2(20);
BEGIN
♦Scalar (*)
♦Composite
♦LOB
3. A datatype specifies and restricts the possible data values that can be assigned to a variable.
True or False?
♦True (*)
♦False
♦CLOB
♦VARCHAR2
♦RECORD (*)
♦DATE
♦Multi
♦Large
♦Single (*)
♦Array
♦Character (*)
♦Table
♦Date (*)
♦Boolean (*)
2.04. Using scalar data type
1. If you use the %TYPE attribute, you can avoid hard-coding the column name. True or False?
♦True
♦False (*)
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_count BINARY_INTEGER;
♦VARCHAR2
♦BOOLEAN (*)
♦CHAR
♦LONG
4. Code is easier to read if you declare one identifier per line. True or False?
♦True (*)
♦False
5. When declared using %TYPE, a variable will inherit ____ from the column on which it is based.
1. 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
♦No, because every column must be prefixed by its table alias, for example: e.last_name.
♦Yes, Oracle will resolve which department_id column comes from which table.
3. Table aliases can be used to shorten the syntax in join statements. True or False?
♦True (*)
♦False
4. What does the following statement return?
ORDER BY e.department_id;
♦Returns all departments, even if there are no employees in the department. (*)
♦Returns all employees, even if they have not been assigned to a department.
♦Simple join
♦Equijoin
♦Nonequijoin (*)
♦Outer join
6. A nonequijoin combines tables that have one or more exact matching columns. True or False?
♦True
♦False (*)
7. 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?
♦20
♦10
♦200 (*)
♦120
8. What type of join returns rows for one table even when there are no matching rows in the
other table?
♦Simple join
♦Equijoin
♦Nonequijoin
♦The hire date of the newest (most recently hired) employee. (*)
2. Group functions cannot be used in subqueries because they contain too many rows. True or
False?
♦True
♦False (*)
3. Which of the following SQL statements will display the name and a total of people with the
same last name?
FROM EMPLOYEES
GROUP BY last_name; (*)
FROM EMPLOYEES
GROUP BY last_name;
FROM EMPLOYEES
GROUP BY last_name;
FROM EMPLOYEES
GROUP BY last_name;
♦ALL (*)
♦=
♦<>
♦>
5. The following EMPLOYEE_ID, SALARY, and COMMISSION_PCT data in the EMPLOYEES table for
six employees.
149, 10500, .2
174, 11000, .3
176, 8600, .2
FROM employees
♦0.2125 (*)
♦The statement will fail because you cannot use more than one group function in a single
statement.
♦0.2521
SELECT last_name
FROM employees
♦The names of employees who earn more than every IT Programmer. (*)
♦The names of employees who earn more than at least one IT Programmer.
♦The names of employees who earn more than half of the IT Programmers.
7. When using a subquery, the =ANY and IN operators are logically identical; they will always give
the same result as each other. True or False?
♦True (*)
♦False
8. Read the following SELECT statement. Choose the column or columns that MUST be included in
the GROUP BY clause.
FROM wf_countries
GROUP BY ?????
♦region_id, COUNT(country_id)
♦region_id,country_id
♦country_id
♦region_id (*)
1. The LENGTH and ROUND functions can be used in PL/SQL statements. True or False?
♦True (*)
♦False
2. The TO_CHAR function is used for explicit data type conversions. True or False?
♦True (*)
♦False
♦True
♦False (*)
BEGIN
v_new_date := ‘Today’;
DBMS_OUTPUT.PUT_LINE(v_new_date);
END;
DECLARE
v_date DATE;
BEGIN
END;
♦v_date := FROM_CHAR(v_char,’dd/mm/yy’);
♦v_date := v_char;
♦TO_DATE
♦TO_NUMBER (*)
♦TO_CHAR
♦Concatenation (*)
♦Exception
♦Exponential (*)
♦Arithmetic (*)
8. Which of the following data type conversions can be done implicitly? (Choose two.)
♦DATE to NUMBER
♦True
♦False (*)
♦v_family_name = SMITH;
♦V_FAMILY_NAME = SMITH;
♦v_family_name := SMITH;
11. 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
♦45
♦29
♦25 (*)
♦14
13. The DECODE and MAX functions can be used in PL/SQL statements. True or False?
♦True
♦False (*)
14. When PL/SQL converts data automatically from one data type to another, it is called _______
conversion.
♦Explicit
♦Implicit (*)
♦TO_CHAR
15. Which of the following statements about implicit conversions is NOT true?
♦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.
1. The LENGTH and ROUND functions can be used in PL/SQL statements. True or False?
♦True (*)
♦False
2. The TO_CHAR function is used for explicit data type conversions. True or False?
♦True (*)
♦False
♦True
♦False (*)
BEGIN
v_new_date := ‘Today’;
DBMS_OUTPUT.PUT_LINE(v_new_date);
END;
♦The block will fail because the character value “Today” cannot be implicitly converted to a date.
(*)
DECLARE
v_date DATE;
BEGIN
END;
♦v_date := FROM_CHAR(v_char,’dd/mm/yy’);
♦TO_DATE
♦TO_NUMBER (*)
♦TO_CHAR
♦Concatenation (*)
♦Exception
♦Exponential (*)
♦Arithmetic (*)
8. Which of the following data type conversions can be done implicitly? (Choose two.)
♦DATE to NUMBER
♦True
♦False (*)
♦v_family_name = SMITH;
♦V_FAMILY_NAME = SMITH;
♦v_family_name := SMITH;
11. 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
♦45
♦29
♦25 (*)
♦14
13. The DECODE and MAX functions can be used in PL/SQL statements. True or False?
♦True
♦False (*)
14. When PL/SQL converts data automatically from one data type to another, it is called _______
conversion.
♦Explicit
♦Implicit (*)
♦TO_CHAR
15. Which of the following statements about implicit conversions is NOT true?
♦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.
1. 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.
♦The outer block is bypassed and the exception is always propagated to the calling environment.
2. 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
DBMS_OUTPUT.PUT_LINE(x);
END;
♦10
♦20
♦15 (*)
♦Nothing is displayed
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 6;
DECLARE
v_hervar NUMBER;
BEGIN
v_hervar := 4;
END;
END;
♦Neither block
4. 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_1 := 8;
END;
var_1 := 12;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(var_1);
END;
♦Unhappy
♦12
♦8
♦4 (*)
5. 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
BEGIN
DECLARE
v_myvar NUMBER := 8;
BEGIN
— Line A
END;
END;
♦At Line A, code:
v_myvar := 25;
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.
6. 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.
DECLARE
v_mynum NUMBER;
BEGIN
v_mynum := 7;
DECLARE
v_mynum NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_mynum);
v_mynum := 3;
END;
DBMS_OUTPUT.PUT_LINE(v_mynum);
END;
♦3,3
♦3,7
♦Null, 7 (*)
♦Null, 3
DECLARE
v_a NUMBER;
BEGIN
v_a := 27;
<>
BEGIN
v_a := 15;
END;
♦Variable v_a is out of scope within the inner block and therefore cannot be referenced.
1. Comments change how a PL/SQL program executes, so an unsuitable comment can cause the
program to fail. True or False? (1) Points
True
False (*)
BEGIN
FROM employees
END;
(1) Points
4. Which of the following are examples of good programming practice? (Choose two.) (1) Points
Use the %TYPE attribute to declare a variable according to another previously declared variable
or database column. (*)
Declare one or more identifiers per line for improved performance.
5. Which of the following are examples of good programming practice? (Choose three.) (1)
Points
6. Which of the following makes PL/SQL code easier to read and maintain? (1) Points
Two variables with the same name can be declared in an outer block and an inner block. True or
False
(1/1) Puntos
True (*)
False
1. When inserting a row into a table, the VALUES clause must include a value for every column of
the table. True or False? (1) Points
True
False (*)
2. What would be the result of the following statement: DELETE employees; (1) Points
3. Is it possible to insert more than one row at a time using an INSERT statement with a VALUES
clause? (1) Points
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.
USING new_emps ne
ON (e.employee_id = ne.employee_id)
WHEN MATCHED
(1) Points
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. (*)
5. You want to modify existing rows in a table. Which of the following are NOT needed in your
SQL statement? (Choose two). (1) Points
A MODIFY clause.
An UPDATE clause.
A new value for the column you want to modify (this can be an expression or a subquery).
DELETE from employees WHERE salary > (SELECT MAX(salary) FROM employees);
(1) Points
You cannot use inequality operators such as "<" and ">" inside a DELETE statement.
USING new_trans nt
OLD_TRANS is the source table and NEW_TRANS is the target table. True or false?
(1) Points
True
False (*)
8. To modify an existing row in a table, you can use the ________ statement. (1) Points
MODIFY
INSERT
ALTER
UPDATE (*)
When explicitly inserting a row into a table, the VALUES clause must include a value for every
column of the table.
False*
It is good programming practice to create identifiers having the samen name as column names
False*
1. PL/SQL is an Oracle proprietary, procedural, 4GL programming language. True or False? (1)
Points
True
False (*)
2. PL/SQL extends SQL by including all of the following except: (1) Points
variables
conditional statements
3. Which of the following statements about PL/SQL and SQL is true? (1) Points
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. (*)
4. Using Oracle Application Express, you can create Web applications that include PL/SQL. True or
False? (1) Points
True (*)
False
5. The fact that PL/SQL is portable is a good thing because: (1) Points
PL/SQL code can be developed on one platform and deployed on another (*)
6. Which of the following can you use PL/SQL to do? (1) Points
7. Which of the following tools can NOT be used to develop and test PL/SQL code? (1) Points
Oracle Jdeveloper
Oracle iSQL*Plus
BEGIN
END;
(1) Points
procedure
subroutine
function
anonymous (*)
1. END;
2. EXCEPTION
3. DECLARE
4. BEGIN
(1) Points
2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
10. Which lines of code will correctly display the message "The cat sat on the mat"? (Choose
two.) (1) Points (Choose all correct answers)
11. What is the purpose of using DBMS_OUTPUT.PUT_LINE in a PL/SQL block? (1) Points
12. Errors are handled in the Exception part of the PL/SQL block. True or False? (1) Points
True (*)
False
13. Type of a variable determines the range of values the variable can have and the set of
operations that are defined for values of the type. (1) Points
True (*)
False
14. Which of these are PL/SQL data types? (Choose three.) (1) Points (Choose all correct
answers)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
Scalar
Composite
Reference
LOB (*)
16. Which of the following are valid identifiers? (Choose two.) (1) Points (Choose all correct
answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
17. Which of the following are PL/SQL lexical units? (Choose two.) (1) Points (Choose all correct
answers)
Identifiers (*)
Table Columns
Reserved Words (*)
Anonymous Blocks
SQL Workshop
18. Delimiters are _____ that have special meaning to the Oracle database. (1) Points
identifiers
variables
symbols (*)
19. When nested blocks are used, which blocks can or must be labeled? (1) Points
The inner block must be labeled, the outer block can be labeled.
The outer block must be labeled if it is to be referred to in the inner block. (*)
<<outer>>
DECLARE
BEGIN
<<inner>> DECLARE
BEGIN
END;
DBMS_OUTPUT.PUT_LINE(inner.v_myvar);
END;
(1) Points
HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the outer block. (*)
21. In the following code, Line A causes an exception. What value will be displayed when the code
is executed?
DECLARE
BEGIN
DECLARE
inner_var NUMBER;
BEGIN
END;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(outer_var);
END;
(1) Points
My
My name (*)
My name is
My name is Zeynep
DECLARE
x VARCHAR2(6) := 'Chang';
BEGIN
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
Susan
Chang (*)
ChangChang
SusanChang
23. Examine the following code. Line A causes an exception. What will be displayed when the
block is executed?
DECLARE
var_a NUMBER := 6;
var_b DATE;
BEGIN
var_a := var_a * 2;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(var_a);
END;
(1) Points
12 (*)
24
24. To comment a single line of code, use two dashes after the comment. True or False? (1)
Points
True
False (*)
25. Which of the following will help to make code easier to read? (1) Points
Naming variables.
Using %Type.
26. Using standards for naming conventions is recommended. True or False? (1) Points
True (*)
False
27. If today's date is 14th June 2007, which statement will correctly convert today's date to the
value: June 14, 2007 ? (1) Points
TO_CHAR(sysdate)
TO_DATE(sysdate)
28. Examine the following code. What is the final value of V_MYBOOL ?
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
END;
(1) Points
True (*)
False
29. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
(1) Points
81
49
14 (*)
18
30. Single row character functions are valid SQL functions in PL/SQL. True or False? (1) Points
True (*)
False
31. The implicit data type conversion at Point A may not work correctly. Why not?
DECLARE
v_mydate DATE;
BEGIN
END;
(1) Points
Oracle cannot implicitly convert a character string to a date, even if the string contains a valid
date value
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
(1) Points
'300'
300 (*)
NULL
33. When you use a function to convert data types in a PL/SQL program, it is called ______
conversion. (1) Points
Explicit (*)
Implicit
TO_CHAR
34. TO_NUMBER, TO_CHAR, and TO_DATE are all examples of: (1) Points
Character functions
Operators
35. Assignment statements can continue over several lines in PL/SQL. True or False? (1) Points
True (*)
False
36. When a variable is defined using the NOT NULL keywords, the variable must contain a value.
True or False? (1) Points
True (*)
False
DECLARE
(1) Points
Correct.
38. Variables can be used in the following ways in a PL/SQL block. (Choose two.) (1) Points
To comment code.
39. A variable must have a value if NOT NULL is specified. True or False? (1) Points
True (*)
False
40. You need to declare a variable to hold a value which has been read from the SALARY column
of the EMPLOYEES table. Which of the following is an advantage of declaring the variable as:
employees.salary%TYPE ? (1) Points
It is shorter than coding NUMBER(8,2)
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
DECLARE
v_result employees.salary%TYPE;
BEGIN
(1) Points
SELECT salary
INTO v_result
FROM employees;
SELECT salary
INTO v_result
FROM employees
INTO v_result
FROM employees
SELECT SUM(salary)
INTO v_result
43. 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;
BEGIN
FROM employees
END;
(1) Points
True
False (*)
44. Which one of these SQL statements can be directly included in a PL/SQL executable block? (1)
Points
WHERE employee_id=100;
DESCRIBE employees;
UPDATE employees
45. Which of the following is NOT a good guideline for retrieving data in PL/SQL? (1) Points
Specify the same number of variables in the INTO clause as database columns in the SELECT
clause.
BEGIN
SAVEPOINT XA;
VALUES ('NV','Neverland');
COMMIT;
ROLLBACK TO XA;
END;
(1) Points
BEGIN
VALUES ('NV','Neverland');
COMMIT;
COMMIT;
ROLLBACK;
END;
(1) Points
You have nothing new; the last ROLLBACK undid the INSERTs.
You have the rows added twice; there are four new rows.
48. Which SQL statement can NOT use an implicit cursor? (1) Points
A DELETE statement
An UPDATE statement
FROM employees
WHERE employee_id=100;
What is the value of SQL%ISOPEN immediately after the SELECT statement is executed?
(1) Points
True
False (*)
Null
50. There are no employees in Department 77. What will happen when the following block is
executed?
BEGIN
WHERE department_id=77;
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
END;
(1) Points
1. Look at this SQL statement: MERGE INTO old_trans ot USING new_trans nt ON (ot.trans_id =
nt.trans_id) …. ; OLD_TRANS is the source table and NEW_TRANS is the target table. True or false?
♦True
♦False (*)
2. You want to modify existing rows in a table. Which of the following are NOT needed in your SQL
statement? (Choose Two)
♦A MODIFY clause (*)
♦A new value for the column you want to modify (this can be an expression or a subquery).
3. 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.
DELETE from employees WHERE salary > (SELECT MAX(salary) FROM employees);
♦You cannot use inequality operators such as “<” and “>” inside a DELETE statement.
5. 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.
6. To modify an existing row in a table, you can use the ________ statement.
♦MODIFY
♦INSERT
♦ALTER
♦UPDATE (*)
8. When inserting a row into a table, the VALUES clause must include a value for every column of
the table. True or False?
♦True
♦False (*)
1. It is good programming practice to create identifiers having the same name as column names.
True or False?
♦True
♦False (*)
2. Does PL/SQL allow you to have a variable with the same name as a database column?
♦No
♦Yes (*)
3. Which SQL statements can be used directly in a PL/SQL block? (Choose two.)
♦GRANT EXECUTE ON …
♦REVOKE SELECT ON …
4. What will happen when the following block is executed? DECLARE v_last employees.last_name
%TYPE; v_first employees.first_name%TYPE; v_salary employees.salary%TYPE; BEGIN SELECT
first_name, last_name INTO v_first, v_last, v_salary FROM employees WHERE employee_id=100;
END;
♦The block will fail because the SELECT statement returns more than one row.
♦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.
5. 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).
♦The SELECT will fail because it does NOT return exactly one row.
♦The block will fail because variable V_SALARY was not declared.
♦The block will fail because no results are displayed to the user.
6. 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.
7. Which one of these SQL statements can be directly included in a PL/SQL executable block?
♦IF… THEN…;
♦SHOW USER;
8. When used in a PL/SQL block, which SQL statement must return exactly one row?
♦INSERT
♦UPDATE
♦SELECT (*)
♦MERGE
♦DELETE
1. Which of the following SQL DML commands can be used inside a PL/SQL block?
2. 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 explicit cursor which must be declared and named by the PL/SQL programmer.
3. 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.
♦DML statements and SELECT statements which return a single row. (*)
5. You can use implicit cursor attributes such as SQL%ROWCOUNT directly inside a DML
statement. For example: INSERT INTO log_table VALUES (SYSDATE, USER, SQL%ROWCOUNT); True
or False?
♦True
♦False (*)
6. 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;
♦An exception is raised because the UPDATE statement did not modify any rows.
SAVEPOINT sp_1;
SAVEPOINT sp_2;
ROLLBACK TO sp_1;
COMMIT;
END;
Which row(s) will be in the ANIMALS table after this block is executed?
♦cool cats
♦One
♦As many as you can execute before the database does an AUTOSAVE.
♦As many as you want until a different DML statement (UPDATE, DELETE or MERGE) is executed.
3. In a PL/SQL block, where can you code a COMMIT statement?♦In any section of the block:
Declaration, Executable, or Exception.
WHERE country_id=’DE’;
END;
♦Two; both the INSERTs are one transaction and both the UPDATEs are a second transaction.
♦It depends on how many rows are updated – there will be a separate transaction for each row.
♦One (*)
1. Which SQL statement is used to remove all the changes made by an uncommitted transaction?
ROLLBACK (*)
2. If a database crashes, all uncommitted changes are automatically rolled back. True or False?
True (*)
True (*)
4. You need not worry about controlling your transactions. Oracle does it all for you. True or False?
False (*)
5. User BOB's CUSTOMERS table contains 20 rows. BOB inserts two more rows into the table but
does not COMMIT his changes. User JANE now executes:
20 (*)
6. A transaction makes several successive changes to a table. If required, you want to be able to
rollback the later changes while keeping the earlier changes. What must you include in your code
to do this?
A savepoint (*)
7. Steven King's row in the EMPLOYEES table has EMPLOYEE_ID = 100 and SALARY = 24000. A user
issues the following statements in the order shown:
UPDATE employees
COMMIT;
UPDATE employees
The user's database session now ends abnormally. What is now King's salary in the table?
48000 (*)
SAVEPOINT Ins_Done;
9. If UserB has privileges to see the data in a table, as soon as UserA has entered data into that
table, UserB can see that data. True or False?
False (*)
10. If Oracle crashes, your changes are automatically rolled back. True or False?
True (*)
11. Which of the following best describes the term "read consistency"?
It prevents other users from seeing changes to a table until those changes have been committed
(*)
12. When you logout of Oracle, your data changes are automatically rolled back. True or False?
False (*)
13. Table MYTAB contains only one column of datatype CHAR(1). A user executes the following
statements in the order shown.
COMMIT;
ROLLBACK;
A dan B (*)
SAVEPOINT Del_Done;
SAVEPOINT upd1_done;
SAVEPOINT upd2_done;
You want to retain all the employees with a salary of 15000; What statement would you execute
next?
BlogThis!
Berbagi ke Twitter
Berbagi ke Facebook
Bagikan ke Pinterest
True (*)
2. Which of these SQL functions used to manipulate strings is NOT a valid regular expression
function ?
REGEXP (*)
3. REGULAR EXPRESSIONS can be used on CHAR, CLOB, and VARCHAR2 datatypes? (True or False)
True (*)
4. Which of the following privileges must be assigned to a user account in order for that user to
connect to an Oracle database?
5. By Controlling User Access with Oracle Database Security, you can give access to specific Objects
in the Database. True or False?
True (*)
6. You want to grant privileges to user CHAN that will allow CHAN to update the data in the
EMPLOYEES table. Which type of privileges will you grant to CHAN?
INSERT (*)
SELECT (*)
9. The database administrator wants to allow user Marco to create new tables in his own schema.
Which privilege should be granted to Marco?
GRANT (*)
11. Which keyword would you use to grant an object privilege to all database users?
PUBLIC (*)
12. To join a table in your database to a table on a second (remote) Oracle database, you need to
use:
True (*)
14. Scott King owns a table called employees. He issues the following statement:
Allison Plumb has been granted CREATE SESSION by the DBA. She logs into the database and issues
the following statement:
True (*)
15. What Oracle feature simplifies the process of granting and revoking privileges?
Role (*)
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 3 Quiz
(1) Points
Specify the same number of variables in the INTO clause as database columns
Correct Correct
(1) Points
WHERE department_id=60;
WHERE department_id=60;
(*)
Correct Correct
DECLARE
v_holdit employees.last_name%TYPE;
BEGIN ...
(1) Points
SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100;
(*)
SELECT last_name
INTO v_holdit
FROM employees;
SELECT *
INTO v_holdit
FROM employees;
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
Correct Correct
(1) Points
SELECT (*)
MERGE
DELETE
UPDATE
INSERT
Correct Correct
(1) Points
Specify the same number of variables in the INTO clause as database columns
in the SELECT clause.
Correct Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 3 Quiz
for Review
(1) Points
Correct Correct
7. How many INSERTs can you have in one transaction? Mark for
Review
(1) Points
One
As many as you want until a different DML statement (UPDATE, DELETE or MERGE)
is executed.
Correct Correct
FROM employees
WHERE employee_id=100;
What is the value of SQL%FOUND immediately after the SELECT statement is executed?
(1) Points
False
Null
True (*)
Correct Correct
(1) Points
True
False (*)
Correct Correct
10. There are no employees in Department 77. What will happen when
BEGIN
WHERE department_id=77;
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT)
END;
(1) Points
A NULL is displayed.
An exception is raised because the block does not contain a COMMIT statement.
Correct Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 3 Quiz
(stud_id NUMBER(6),
last_name VARCHAR2(20),
first_name VARCHAR2(20),
lunch_num NUMBER(4));
(1) Points
(*)
Correct Correct
12. To modify an existing row in a table, you can use the ________
INSERT
ALTER
MODIFY
UPDATE (*)
Correct Correct
13. Which of the following will delete all employees who work in the
(1) Points
WHERE department_id =
(SELECT department_id
FROM departments
(*)
WHERE department_id =
SELECT department_id
FROM departments
FROM departments
FROM employees;
USING all_objects b
ON (a.object_id = b.object_id)
WHEN MATCHED
THEN UPDATE
(1) Points
UPDATE
MERGE (*)
DELETE
INSERT
15. When explicitly inserting a row into a table, the VALUES clause must include a value for every
column of the table. True or False? Mark for Review (1) Points True False (*)
The MERGE statement will INSERT or DELETE rows in a target table based on matching
values in a source table. True or False?
(1/1) Puntos
True
False (*)
If a DELETE statement does not include a WHERE clause, all rows in the table
are deleted.
True*
When INSERTing a row, the NULL keyword can be included in the VALUES (....)
list. True or False?
False*
13. Which implicit cursor attribute identifies the number of rows updated in the following
statement?
(1/1) Puntos
SQL%ROWCOUNT (*)
SQL%COUNT
SQLROW%COUNT
SQL%NUMBER
2. 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
3. We want to execute one of three statements depending on whether the value in V_VAR is 10,
20 or some other value. What should be coded at Line A? IF v_var = 10 THEN statement1; — Line A
statement2; ELSE statement3; END IF;♦ELSE IF v_var = 20 THEN
♦ELSIF v_var = 20
4. 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
♦Start
♦Nothing will be displayed. The block will fail because you cannot compare two null values.
5. 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. (*)
6. Which of the following statements are true about PL/SQL conditional control structures such as
IF … , CASE … and loops?
♦They allow the programmer to use logical tests to determine which statements are executed and
which are not.
♦They allow a set of statements to be executed repeatedly (i.e. more than once).
END IF;
DBMS_OUTPUT.PUT_LINE(mature);
What will be displayed when this code is executed?
♦child
♦teenager
♦adult (*)
♦adultteenagerchild
IF (v_job=’President’)
♦ELSE is missing
IF (v_job=’President’)
♦ELSE is missing
DECLARE
v_age1 NUMBER(3);
v_age2 NUMBER(3);
v_message VARCHAR2(20);
BEGIN
CASE
END CASE;
DBMS_OUTPUT.PUT_LINE(v_message);
END;
♦Equal
♦Undefined (*)
♦Unequal
DECLARE
v_age NUMBER(3);
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’;
END CASE;
DBMS_OUTPUT.PUT_LINE(v_status);
END;
♦Adult Male
♦Junior Female
♦Other Value (*)
DECLARE
v_score NUMBER(3);
v_grade CHAR(1);
BEGIN
— 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?
♦END; (*)
♦ENDIF;
♦END CASE;
♦ENDCASE;
♦END;
♦END IF;
♦ENDCASE;
v_a BOOLEAN;
v_c BOOLEAN ;
BEGIN
— 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
♦An error will occur because you cannot combine two Boolean variables using “NOT”.
♦None.
♦One only.
♦Two.
DECLARE
v_count NUMBER := 0;
v_string VARCHAR2(20);
BEGIN
LOOP
EXIT;
END IF;
v_count := v_count + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_count);
END;
♦9
♦10 (*)
♦11
♦xxxxxxxxxxx
LOOP
i := i + 1;
END LOOP;
♦A FOR loop.
♦A WHILE loop.
♦A nested loop.
DECLARE
v_result NUMBER;
BEGIN
LOOP
v_count := v_count – 1;
v_result := v_count * 2;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_result);
END;
♦8
♦10 (*)
♦12
♦NULL
DECLARE
BEGIN
LOOP
END LOOP;
END;
♦Once.
♦Twice.
♦An infinite number of times because the EXIT condition will never be true
6. You want to calculate and display the multiplication table for “sevens”: 7×1=7, 7×2=14, 7×3=21
and so on. Which kind of PL/SQL construct is best for this?
♦A loop (*)
♦A CASE statement
♦A Boolean variable.
8. For which one of these tasks should you use a PL/SQL loop?
♦Executing the same set of statements repeatedly until a condition becomes true. (*)
♦When an implicitly declared counter must increase by 1 in each iteration of the loop. (*)
♦When we want to exit from the loop when a Boolean variable becomes FALSE.
♦When the statements inside the loop must execute at least once.
DECLARE
BEGIN
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
♦4/30/2007 (*)
♦4/17/2007
FOR i IN 1 .. 3 LOOP
i := 4;
END LOOP;
♦One
♦Three
♦Four
♦The block will fail because you cannot change the value of i inside the loop. (*)
i := 2;
i := 4;
END LOOP;
♦No lines
♦Two lines
♦The block will fail because you cannot use DBMS_OUTPUT.PUT_LINE inside a loop.
5. 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
6. You should use a WHILE loop when the number of iterations of the loop is known in advance.
True or False?
♦True
♦False (*)
7. In a WHILE loop, the controlling condition is checked at the start of each iteration. True or
False?
♦True (*)
♦False
DECLARE
v_blue NUMBER(3) := 0;
v_red NUMBER(3) := 0;
BEGIN
<<blue>> LOOP
v_blue := v_blue + 1;
<<red>> LOOP
v_red := v_red + 1;
— Line A
END;
What should you code at Line A to exit from the outer loop?
♦EXIT;
♦EXIT red;
♦EXIT <<blue>>;
2. When the following code is executed, how many lines of output will be displayed?
BEGIN
END LOOP;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
♦80
♦45 (*)
♦14
♦41
DECLARE
x NUMBER(6) := 0 ;
BEGIN
x := x+1 ;
END LOOP;
END LOOP;
DBMS_OUTPUT.PUT_LINE(x);
END;
♦5
♦10
♦15
♦50 (*)
♦The outer loop must be labelled, but the inner loop need not be labelled
♦The outer loop must be labelled if you want to exit the outer loop from within the inner loop (*)
5. What statement allows you to exit the outer loop at Point A in the following block?
DECLARE
BEGIN
…
LOOP — inner loop
… — Point A
END LOOP;
END LOOP;
END;
BEGIN
— Point A
END LOOP;
END LOOP;
END;
♦LOOP
True
False (*)
variables
conditional statements
constants
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. (*)
4. Using Oracle Application Express, you can create Web applications that include PL/SQL. True
or False?
True (*)
False
PL/SQL code can be developed on one platform and deployed on another (*)
7. Which of the following tools can NOT be used to develop and test PL/SQL code?
Oracle Jdeveloper
Oracle iSQL*Plus
BEGIN
END;
procedure
subroutine
function
anonymous (*)
1. END;
2. EXCEPTION
3. DECLARE
4. BEGIN
2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
10. Which lines of code will correctly display the message "The cat sat on the mat"? (Choose
two.)
12. Errors are handled in the Exception part of the PL/SQL block. True or False?
True (*)
False
13. Type of a variable determines the range of values the variable can have and the set of
operations that are defined for values of the type.
True (*)
False
14. Which of these are PL/SQL data types? (Choose three.) (Choose all correct answers)
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
Scalar
Composite
Reference
LOB (*)
16. Which of the following are valid identifiers? (Choose two.) (Choose all correct answers)
yesterday (*)
yesterday's date
number_of_students_in_the_class
v$testresult (*)
#students
17. Which of the following are PL/SQL lexical units? (Choose two.) (Choose all correct answers)
Identifiers (*)
Table Columns
Anonymous Blocks
SQL Workshop
18. Delimiters are _____ that have special meaning to the Oracle database.
identifiers
variables
symbols (*)
19. When nested blocks are used, which blocks can or must be labeled?
The inner block must be labeled, the outer block can be labeled.
The outer block must be labeled if it is to be referred to in the inner block. (*)
<<outer>>
DECLARE
BEGIN
<<inner>> DECLARE
BEGIN
END;
DBMS_OUTPUT.PUT_LINE(inner.v_myvar);
END;
HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the outer block. (*)
21. In the following code, Line A causes an exception. What value will be displayed when the
code is executed?
DECLARE
BEGIN
outer_var := outer_var || ' name';
DECLARE
inner_var NUMBER;
BEGIN
END;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(outer_var);
END;
My
My name (*)
My name is
My name is Zeynep
DECLARE
x VARCHAR2(6) := 'Chang';
BEGIN
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
DBMS_OUTPUT.PUT_LINE(x);
END;
Susan
Chang (*)
ChangChang
SusanChang
23. Examine the following code. Line A causes an exception. What will be displayed when the
block is executed?
DECLARE
var_a NUMBER := 6;
var_b DATE;
BEGIN
var_a := var_a * 2;
var_a := var_a * 2;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(var_a);
END;
12 (*)
24
24. To comment a single line of code, use two dashes after the comment. True or False?
True
False (*)
25. Which of the following will help to make code easier to read?
Naming variables.
Using %Type.
True (*)
False
27. If today's date is 14th June 2007, which statement will correctly convert today's date to the
value: June 14, 2007 ?
TO_CHAR(sysdate)
TO_DATE(sysdate)
28. Examine the following code. What is the final value of V_MYBOOL ?
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
END;
True (*)
False
29. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;
81
49
14 (*)
18
30. Single row character functions are valid SQL functions in PL/SQL. True or False?
True (*)
False
31. The implicit data type conversion at Point A may not work correctly. Why not?
DECLARE
v_mydate DATE;
BEGIN
END;
Oracle cannot implicitly convert a character string to a date, even if the string contains a valid
date value
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
'300'
300 (*)
NULL
33. When you use a function to convert data types in a PL/SQL program, it is called ______
conversion.
Explicit (*)
Implicit
TO_CHAR
Character functions
Operators
35. Assignment statements can continue over several lines in PL/SQL. True or False?
True (*)
False
36. When a variable is defined using the NOT NULL keywords, the variable must contain a value.
True or False?
True (*)
False
DECLARE
Correct.
38. Variables can be used in the following ways in a PL/SQL block. (Choose two.) (Choose all
correct answers)
To comment code.
39. A variable must have a value if NOT NULL is specified. True or False?
True (*)
False
40. You need to declare a variable to hold a value which has been read from the SALARY column
of the EMPLOYEES table. Which of the following is an advantage of declaring the variable as:
employees.salary%TYPE ?
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
It executes much faster than using NUMBER(8,2)
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
DECLARE
v_result employees.salary%TYPE;
BEGIN
SELECT salary
INTO v_result
FROM employees;
SELECT salary
INTO v_result
FROM employees
SELECT salary
INTO v_result
FROM employees
INTO v_result
43. 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;
BEGIN
FROM employees
END;
True
False (*)
44. Which one of these SQL statements can be directly included in a PL/SQL executable block?
WHERE employee_id=100;
DESCRIBE employees;
UPDATE employees
45. Which of the following is NOT a good guideline for retrieving data in PL/SQL?
Specify the same number of variables in the INTO clause as database columns in the SELECT
clause.
BEGIN
SAVEPOINT XA;
VALUES ('NV','Neverland');
COMMIT;
ROLLBACK TO XA;
END;
BEGIN
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.
A DELETE statement
An UPDATE statement
FROM employees
WHERE employee_id=100;
What is the value of SQL%ISOPEN immediately after the SELECT statement is executed?
True
False (*)
Null
Error. That attribute does not apply for implicit cursors.
50. There are no employees in Department 77. What will happen when the following block is
executed?
BEGIN
WHERE department_id=77;
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
END;
A NULL is displayed.
An exception is raised because the block does not contain a COMMIT statement.
DECLARE
v_counter NUMBER(4) := 0;
BEGIN
... Line A
...
END;
(1) Points
2. In a WHILE loop, the statements inside the loop must execute at least once. True or False? (1)
Points
True
False (*)
3. Which of the following blocks produces the same output as this block?
BEGIN
FOR i in 1 .. 3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
(1) Points
DECLARE
i PLS_INTEGER := 0;
BEGIN
DBMS_OUTPUT.PUT_LINE(i);
i := i + 1;
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END; (*)
DECLARE
i PLS_INTEGER := 0;
BEGIN
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
i := i+ 1;
END;
4. When using a counter to control a FOR loop, which of the following is true ? (1) Points
You must have exactly one counter but it is implicitly declared. (*)
You must have exactly one counter and you must explicitly declare it.
You can have multiple counters, but you need at least one.
You don't need a counter; you can test for anything (for example, whether a BOOLEAN is TRUE
or FALSE).
5. In a FOR loop, an implicitly declared counter automatically increases or decreases with each
iteration. True or False? (1) Points
True (*)
False
6. You want to display a message which depends on the value of v_grade: if v_grade = 'A' display
'Very Good', if v_grade = 'B' then display 'Good', and so on.
DECLARE
v_grade CHAR(1);
BEGIN
CASE v_grade
(1) Points
IF 'A' THEN
7. You want to assign a value to v_result which depends on the value of v_grade: if v_grade = 'A'
set v_result to 'Very Good' and so on.
DECLARE
v_grade CHAR(1);
v_result VARCHAR2(10);
BEGIN
v_result :=
CASE v_grade
(1) Points
DECLARE
v_result VARCHAR2(10);
BEGIN
CASE v_grade
END CASE;
END;
(1) Points
Poor
In Between (*)
Null
Very Good
9. What will be the value of variable c after the following code is executed?
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := FALSE;
c NUMBER;
BEGIN
c :=
CASE
WHEN a OR b THEN 30
ELSE 40
END CASE;
END;
(1) Points
30 (*)
20
40
10
10. Which of the following is NOT a characteristic of a CASE statement? (1) Points
DECLARE
v_salary NUMBER(6);
BEGIN
v_result := 'HIGH';
ELSE
v_result := 'LOW';
END IF;
END;
What is the final value of v_result?
(1) Points
HIGH
LOW (*)
MIDDLE
Null
IF condition
THEN statement1
ELSE statement 2;
IF condition
THEN statement1
ELSE statement 2;
END IF;
IF condition;
THEN statement1;
ELSE statement2;
END IF;
ELSE statement2;
IF condition;
THEN statement;
END IF;
IF condition
THEN statement
ENDIF;
DECLARE
a VARCHAR2(6) := NULL;
b VARCHAR2(6) := NULL;
BEGIN
IF a = b THEN
DBMS_OUTPUT.PUT_LINE('EQUAL');
ELSIF a != b THEN
DBMS_OUTPUT.PUT_LINE('UNEQUAL');
ELSE
DBMS_OUTPUT.PUT_LINE('OTHER');
END IF;
END;
(1) Points
UNEQUAL
EQUAL
OTHER (*)
15. How many ELSIF statements are you allowed to have in a compound IF statement? (1) Points
Only one
They must match the same number as the number of ELSE statements.
16. You need to execute a set of statements 10 times, increasing a counter by 1 each time. Which
of the following PL/SQL constructs can do this? (Choose three) (1) Points (Choose all correct
answers)
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := FALSE;
c BOOLEAN := TRUE;
d BOOLEAN := FALSE;
END IF;
(1) Points
NULL
'won'
'lost' (*)
False
FOR loop
Basic loop
WHILE loop
DECLARE
v_counter PLS_INTEGER := 1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(v_counter);
v_counter := v_counter + 1;
END LOOP;
END;
What is the last value of V_COUNTER that is displayed?
(1) Points
4 (*)
20. What kind of statement is best suited for displaying the multiplication table for "sixes": 6x1=6,
6x2=12 ... 6x12=72? (1) Points
CASE expression
IF statement
CASE statement
Section 4
v_counter := 1;
LOOP
v_counter := v_counter + 1;
END LOOP;
(1) Points
5
v_count := 1;
LOOP
v_count := v_count + 1;
END LOOP;
(1) Points
FOR loop
IF-THEN loop
WHILE loop
CASE loop
BEGIN
EXIT WHEN j = 7;
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
How many lines of output will be displayed when this code is executed?
(1) Points
35
30 (*)
40
DECLARE
v_outer_count NUMBER := 1;
v_inner_count NUMBER := 1;
BEGIN
LOOP
LOOP
v_inner_count := v_inner_count + 1;
END LOOP;
v_outer_count := v_outer_count + 1;
END LOOP;
END;
(1) Points
The inner loop is exited but the outer loop continues execution. (*)
The outer loop is exited but the inner loop continues execution.
DECLARE
i INTEGER := 0;
BEGIN
i := i+1;
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
(1) Points
EXIT <<outerloop>>
EXIT outerloop
EXIT j_loop
26. When coding two nested loops, both loops must be of the same type. For example, you
cannot code a FOR loop inside a WHILE loop. True or False? (1) Points
True
False (*)
Section 5
27. You want to declare a cursor which locks each row fetched by the cursor. Examine the
following code:
DECLARE
CURSOR emp_curs IS
FOR -- Point A
(1) Points
UPDATE;
UPDATE OF salary;
UPDATE NOWAIT;
After opening the cursor and fetching some rows, you want to delete the most recently fetched
row. Which of the following will do this successfully?
(1) Points
29. User TOM has locked a row in the WORKERS table. Now, user DICK wants to open the
following cursor:
CURSOR c IS
(1) Points
TOM's session is rolled back. DICK's session successfully fetches rows from the cursor.
Both sessions wait for a few seconds; then the system breaks all locks and both sessions raise an
exception.
30. For which type of SQL statement must you use an explicit cursor? (1) Points
v_salary employees.salary%TYPE;
BEGIN
OPEN emp_curs;
CLOSE emp_curs;
END;
(1) Points
The block will fail and an INVALID_CURSOR exception will be raised. (*)
OPEN my_curs;
CLOSE my_curs;
(1) Points
C,D,A,B
C,A,D,B (*)
A,C,D,B
C,A,B,D
33. Which of these constructs can be used to fetch multiple rows from a cursor's active set? (1)
Points
A CASE statement
A basic loop which includes FETCH and EXIT WHEN statements (*)
DECLARE
CURSOR emp_curs IS
SELECT last_name, salary
FROM employees
ORDER BY salary;
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
...
Which of the following statements successfully opens the cursor and fetches the first row of the
active set?
(1) Points
OPEN emp_curs;
OPEN emp_curs;
OPEN emp_curs;
OPEN emp_curs;
FETCH emp_curs;
DECLARE
CURSOR emp_curs IS
v_salary employees.salary%TYPE;
BEGIN
FETCH emp_curs INTO v_salary;
DBMS_OUTPUT.PUT_LINE(v_salary);
CLOSE emp_curs;
END;
(1) Points
The execution will fail and an error message will be displayed. (*)
36. Which of these statements about implicit cursors is NOT true? (1) Points
37. The employees table contains 20 rows. What will happen when the following code is
executed?
DECLARE
CURSOR emp_curs IS
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
DBMS_OUTPUT.PUT_LINE(v_job_id);
EXIT WHEN emp_curs%NOTFOUND;
END LOOP;
CLOSE emp_curs;
END;
(1) Points
21 rows of output will be displayed; the first job_id will be displayed twice.
21 rows of output will be displayed; the last job_id will be displayed twice. (*)
38. An implicit cursor can be used for a multiple-row SELECT statement. True or False? (1) Points
True
False (*)
(1) Points
p_param := 'ABC';
OPEN c_curs(p_param);
40. What is one of the advantages of using parameters with a cursor? (1) Points
You can use a single cursor to fetch a different set of rows each time the cursor is opened. (*)
41. Which of the following statements about the %ISOPEN cursor attribute is true? (1) Points
You can issue the %ISOPEN cursor attribute only when a cursor is open.
You can issue the %ISOPEN cursor attribute only when more than one record is returned.
You can issue the %ISOPEN cursor attribute when a cursor is open or closed. (*)
42. The DEPARTMENTS table contains four columns. Examine the following code:
DECLARE
CURSOR dept_curs IS
v_dept_rec dept_curs%ROWTYPE;
BEGIN
OPEN dept_curs;
...
(1) Points
43. Which of the following cursor attributes evaluates to TRUE if the cursor is open? (1) Points
%ISOPEN (*)
%NOTFOUND
%FOUND
%ROWCOUNT
44. Which of the following cursor attributes is set to the total number of rows returned so far? (1)
Points
%ISOPEN
%NOTFOUND
%FOUND
%ROWCOUNT (*)
46. Examine the following code. To display the salary of an employee, what must be coded at
Point A?
DECLARE
BEGIN
END LOOP;
END;
(1) Points
salary
emp_curs.salary
emp_rec.salary (*)
employees.salary
emp_rec.salary IN emp_curs
BEGIN
FOR emp_rec IN
DBMS_OUTPUT.PUT_LINE(emp_rec%ROWCOUNT || emp_rec.last_name):
END LOOP;
END;
(1) Points
You cannot use FOR UPDATE NOWAIT with a cursor FOR loop using a subquery.
You cannot reference %ROWCOUNT with a cursor FOR loop using a subquery. (*)
48. When using multiple nested cursors, what kinds of loops can you use? (1) Points
49. How many explicit cursors can be declared and used in a single PL/SQL block? (1) Points
One or two.
Only one.
Up to eight cursors.
50. You want to display all locations, and the departments in each location. Examine the following
code:
DECLARE
BEGIN
FOR loc_rec IN loc_curs LOOP
DBMS_OUTPUT.PUT_LINE(loc_rec.city);
DBMS_OUTPUT.PUT_LINE(dept_rec.department_name);
END LOOP;
END LOOP;
END;
(1) Points
p_loc_id
location_id
null
loc_rec.location_id (*)
What statement allows you to exit the outer loop at Point A in the following block?
DECLARE
BEGIN
...
...
... -- Point A
...
END LOOP;
...
...
END LOOP;
END;
(1) Points
2. Which one of these statements about using nested loops is true? (1) Points
The outer loop must be labelled, but the inner loop need not be labelled
The outer loop must be labelled if you want to exit the outer loop from within the inner loop (*)
DECLARE
x NUMBER(6) := 0 ;
BEGIN
x := x+1 ;
END LOOP;
END LOOP;
DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
10
15
50 (*)
4. When the following code is executed, how many lines of output will be displayed?
BEGIN
END LOOP;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
(1) Points
80
45 (*)
14
41
BEGIN
-- Point A
END LOOP;
END LOOP;
END;
(1) Points
LOOP
DECLARE
v_blue NUMBER(3) := 0;
v_red NUMBER(3) := 0;
BEGIN
v_blue := v_blue + 1;
v_red := v_red + 1;
-- Line A
END;
What should you code at Line A to exit from the outer loop?
(1) Points
EXIT;
EXIT red;
EXIT <<blue>>;
la 16:08 Un comentariu:
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
i := 2;
i := 4;
END LOOP;
(1) Points
No lines
Two lines
The block will fail because you cannot use DBMS_OUTPUT.PUT_LINE inside a loop.
2. Look at the following block:
DECLARE
BEGIN
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?
(1) Points
01-MAY-07
31-DEC-07
4/30/2007 (*)
4/17/2007
3. Which statement best describes when a FOR loop should be used? (1) Points
When an implicitly declared counter must increase by 1 in each iteration of the loop. (*)
When we want to exit from the loop when a Boolean variable becomes FALSE.
When the statements inside the loop must execute at least once.
4. You should use a WHILE loop when the number of iterations of the loop is known in advance.
True or False? (1) Points
True
False (*)
One
Three
Four
The block will fail because you cannot change the value of i inside the loop. (*)
True
False (*)
7. In a WHILE loop, the controlling condition is checked at the start of each iteration. True or
False? (1) Points
True (*)
False
8. You want a loop that counts backwards from 10 through 1. How do you code that? (1) Points
FOR i IN 10 .. 1 LOOP
FOR i IN 1 .. 10 BY -1 LOOP
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
DECLARE
v_result NUMBER;
BEGIN
LOOP
v_count := v_count - 1;
v_result := v_count * 2;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_result);
END;
(1) Points
10 (*)
12
NULL
2. For which one of these tasks should you use a PL/SQL loop? (1) Points
Updating the salary of one employee.
Executing the same set of statements repeatedly until a condition becomes true. (*)
DECLARE
v_date DATE;
BEGIN
LOOP
END LOOP;
END;
(1) Points
Once.
Twice.
An infinite number of times because the EXIT condition will never be true
i := 10;
LOOP
i := i + 1;
EXIT WHEN i > 30;
END LOOP;
(1) Points
A FOR loop.
A WHILE loop.
An infinite loop.
A nested loop.
DECLARE
v_count NUMBER := 0;
v_string VARCHAR2(20);
BEGIN
LOOP
EXIT;
END IF;
v_count := v_count + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_count);
END;
(1) Points
10 (*)
11
xxxxxxxxxxx
6. 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? (1) Points
A loop (*)
A CASE statement
A Boolean variable.
8. How many EXIT statements can be coded inside a basic loop? (1) Points
None.
One only.
Two.
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
END; (*)
ENDIF;
END CASE;
ENDCASE;
DECLARE
v_a BOOLEAN;
v_c BOOLEAN ;
BEGIN
-- Line A
....
END;
(1) Points
True
False (*)
NULL
Undefined
DECLARE
v_age1 NUMBER(3);
v_age2 NUMBER(3);
v_message VARCHAR2(20);
BEGIN
CASE
END CASE;
DBMS_OUTPUT.PUT_LINE(v_message);
END;
(1) Points
Equal
Undefined (*)
Unequal
DECLARE
v_score NUMBER(3);
v_grade CHAR(1);
BEGIN
-- 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?
(1) Points
DECLARE
v_age NUMBER(3);
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';
END CASE;
DBMS_OUTPUT.PUT_LINE(v_status);
END;
(1) Points
Adult Male
Junior Female
END;
END IF;
ENDCASE;
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.
(1) Points
DECLARE
x BOOLEAN := FALSE;
y BOOLEAN := FALSE;
z BOOLEAN ;
BEGIN
z := (x OR NOT y);
-- Line A
....
END;
(1) Points
True (*)
False
NULL
An error will occur because you cannot combine two Boolean variables using "NOT".
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
1. Name three types of control structures in PL/SQL. (Choose three) (1) Points
SELECT statements
EXCEPTIONS
IF statements (*)
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? (1) Points
IF...THEN...ELSE
IF...THEN...ELSIF...ELSE
CASE...WHEN...THEN
A loop. (*)
3. A basic loop is a type of control structure used to change the logical flow of statements in a
PL/SQL block. True or False? (1) Points
True (*)
False
age := 5;
IF age<30 THEN mature := 'adult';
END IF;
DBMS_OUTPUT.PUT_LINE(mature);
(1) Points
child
teenager
adult (*)
adultteenagerchild
5. Which one of the following is correct syntax for an IF statement? (1) Points
6. We want to execute one of three statements depending on whether the value in V_VAR is 10,
20 or some other value. What should be coded at Line A?
IF v_var = 10 THEN
statement1;
-- Line A
statement2;
ELSE
statement3;
END IF;
(1) Points
ELSIF v_var = 20
IF v_var = 20 THEN
DECLARE
v_birthdate DATE;
BEGIN
THEN
ELSE
END IF;
END;
(1) Points
8. Which of the following statements are true about any of the PL/SQL conditional control
structures such as IF ... , CASE ... and loops? (1) Points
They allow the programmer to use logical tests to determine which statements are executed
and which are not.
They allow a set of statements to be executed repeatedly (i.e. more than once).
IF (v_job='President')
(1) Points
ELSE is missing
DECLARE
BEGIN
v_char:='Equal';
END IF;
DBMS_OUTPUT.PUT_LINE(v_char);
END;
(1) Points
Equal
Start
Nothing will be displayed. The block will fail because you cannot compare two null values.
DECLARE
v_bool2 BOOLEAN;
BEGIN
v_char:='down';
ELSE v_char:='left';
END IF;
DBMS_OUTPUT.PUT_LINE(v_char);
END;
(1) Points
up
down
left (*)
null
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
DECLARE
v_count NUMBER;
BEGIN
END;
No employees earn more than $50,000. Which of the following statements are true? (1) Points
The SELECT will fail because it does NOT return exactly one row.
The block will fail because variable V_SALARY was not declared.
The block will fail because no results are displayed to the user.
2. Which one of these SQL statements can be directly included in a PL/SQL executable block? (1)
Points
IF... THEN...;
SHOW USER;
3. It is good programming practice to create identifiers having the same name as column names.
True or False? (1) Points
True
False (*)
4. Which of the following is NOT a valid guideline for retrieving data in PL/SQL? (1) Points
Specify the same number of variables in the INTO clause as database columns in the SELECT
clause.
5. Which SQL statements can be used directly in a PL/SQL block? (Choose two.) (1) Points
6. Does PL/SQL allow you to have a variable with the same name as a database column? (1)
Points
No
Yes (*)
DECLARE
v_last employees.last_name%TYPE;
v_first employees.first_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
END;
(1) Points
The block will fail because the SELECT statement returns more than one row.
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.
8. When used in a PL/SQL block, which SQL statement must return exactly one row? (1) Points
INSERT
UPDATE
SELECT (*)
MERGE
DELETE
la 15:38 Niciun comentariu:
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
1. When inserting a row into a table, the VALUES clause must include a value for every column of
the table. True or False? (1) Points
True
False (*)
2. What would be the result of the following statement: DELETE employees; (1) Points
3. Is it possible to insert more than one row at a time using an INSERT statement with a VALUES
clause? (1) Points
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.
USING new_emps ne
ON (e.employee_id = ne.employee_id)
WHEN MATCHED
(1) Points
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. (*)
5. You want to modify existing rows in a table. Which of the following are NOT needed in your
SQL statement? (Choose two). (1) Points
A MODIFY clause.
An UPDATE clause.
A new value for the column you want to modify (this can be an expression or a subquery).
(1) Points
You cannot use inequality operators such as "<" and ">" inside a DELETE statement.
USING new_trans nt
OLD_TRANS is the source table and NEW_TRANS is the target table. True or false?
(1) Points
True
False (*)
8. To modify an existing row in a table, you can use the ________ statement. (1) Points
MODIFY
INSERT
ALTER
UPDATE (*)
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Trimiteți către Pinterest
Section 1
1. Comments change how a PL/SQL program executes, so an unsuitable comment can cause the
program to fail. True or False? (1) Points
True
False (*)
DECLARE
BEGIN
FROM employees
END;
(1) Points
4. Which of the following are examples of good programming practice? (Choose two.) (1) Points
Use the %TYPE attribute to declare a variable according to another previously declared variable
or database column. (*)
5. Which of the following are examples of good programming practice? (Choose three.) (1)
Points
6. Which of the following makes PL/SQL code easier to read and maintain? (1) Points
Place multiple statements on the same line.
la 15:27 Un comentariu:
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
1. A variable is global to an outer block and local to the inner block. True or False? (1) Points
True
False (*)
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 6;
DECLARE
v_hervar NUMBER;
BEGIN
v_hervar := 4;
END;
END;
(1) Points
Neither block
DECLARE
v_mynum NUMBER;
BEGIN
v_mynum := 7;
DECLARE
v_mynum NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_mynum);
v_mynum := 3;
END;
DBMS_OUTPUT.PUT_LINE(v_mynum);
END;
(1) Points
3,3
3,7
Null, 7 (*)
Null, 3
4. 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
DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
10
20
15 (*)
Nothing is displayed
5. For the anonymous block below, what is the correct reference to the father's date of birth in
the inner block?
<<outer>>
DECLARE
v_father_name VARCHAR2(20):='Patrick';
v_date_of_birth DATE:='20-Apr-1972';
BEGIN
DECLARE
v_child_name VARCHAR2(20):='Mike';
v_date_of_birth DATE:='12-Dec-2002';
...
(1) Points
v_date_of_birth.outer
<<outer>>v_date_of_birth
<<outer.v_date_of_birth>>
outer.v_date_of_birth (*)
6. 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? (1) Points
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.
The outer block is bypassed and the exception is always propagated to the calling environment.
DECLARE
v_a NUMBER;
BEGIN
v_a := 27;
<<inner_block>>
BEGIN
v_a := 15;
END;
(1) Points
Variable v_a is out of scope within the inner block and therefore cannot be referenced.
8. What happens when an exception occurs in the executable section of a PL/SQL block? (1)
Points
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.
9. 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_1 := 8;
END;
var_1 := 12;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(var_1);
END;
(1) Points
Unhappy
12
4 (*)
10. 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
BEGIN
DECLARE
v_myvar NUMBER := 8;
BEGIN
-- Line A
END;
END;
(1) Points
At Line A, code:
v_myvar := 25;
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.
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
29
25 (*)
14
2. Which explicit function is used to convert a character into a number? (1) Points
TO_DATE
TO_NUMBER (*)
TO_CHAR
True
False (*)
DECLARE
v_date DATE;
BEGIN
END;
(1) Points
v_date := FROM_CHAR(v_char,'dd/mm/yy');
v_date := v_char;
5. When PL/SQL converts data automatically from one data type to another, it is called _______
conversion. (1) Points
Explicit
Implicit (*)
TO_CHAR
6. The DECODE and MAX functions can be used in PL/SQL statements. True or False? (1) Points
True
False (*)
7. Which of the following are valid PL/SQL operators? (Choose three.) (1) Points (Choose all
correct answers)
Concatenation (*)
Exception
Exponential (*)
Arithmetic (*)
8. Which of the following statements about implicit conversions is NOT true? (1) Points
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.
V_FAMILY_NAME = SMITH;
v_family_name := SMITH;
10. The TO_CHAR function is used for explicit data type conversions. True or False? (1) Points
True (*)
False
11. Explicit conversions can be slower than implicit conversions. True or False? (1) Points
True
False (*)
True
False (*)
BEGIN
v_new_date := 'Today';
DBMS_OUTPUT.PUT_LINE(v_new_date);
END;
(1) Points
14. The LENGTH and ROUND functions can be used in PL/SQL statements. True or False? (1)
Points
True (*)
False
15. PL/SQL can implicitly convert a CHAR to a NUMBER, provided the CHAR contains a numeric
value, for example '123'. True or False? (1) Points
True (*)
False
16. Which of the following data type conversions can be done implicitly? (Choose two.) (1)
Points
DATE to NUMBER
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
1. If you use the %TYPE attribute, you can avoid hard-coding the column name. True or False?
(1) Points
True
False (*)
2. Code is easier to read if you declare one identifier per line. True or False? (1) Points
True (*)
False
3. Which of the following is NOT a good guideline for declaring variables? (1) Points
4. Which of the following variable declarations does NOT use a number data type? (1) Points
v_count PLS_INTEGER := 0;
v_median_age NUMBER(6,2);
v_count BINARY_INTEGER;
5. When declared using %TYPE, a variable will inherit ____ from the column on which it is based.
(1) Points
The name of the column
VARCHAR2
BOOLEAN (*)
CHAR
LONG
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
1. Which of the folowing are scalar data types? (Choose three.) (1) Points (Choose all correct
answers)
Array
Character (*)
Table
Date (*)
Boolean (*)
CLOB
VARCHAR2
RECORD (*)
DATE
3. What are the data types of the variables in the following declaration?
DECLARE
fname VARCHAR2(20);
BEGIN
...
(1) Points
Scalar (*)
Composite
LOB
4. A datatype may specify a valid range of values. True or False? (1) Points
True (*)
False
Multi
Large
Single (*)
6. A datatype specifies and restricts the possible data values that can be assigned to a variable.
True or False? (1) Points
True (*)
False
7. Which of the following are PL/SQL data types? (Choose three.) (1) Points (Choose all correct
answers)
Lexical
Scalar (*)
Delimiter
Composite (*)
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
1. What is a lexical unit? (1) Points
A type of variable
Parentheses: ()
True (*)
False
4. Which of the following symbols can be used to enclose a comment in PL/SQL? (1) Points
??
*/ / *
:: ::
/* */ (*)
5. Which of the following are lexical units? (Choose two.) (1) Points (Choose all correct answers)
Data types
PL/SQL blocks
Identifiers (*)
Literals (*)
6. Which of the following is a valid naming convention for an identifier? (Choose two.) (1) Points
(Choose all correct answers)
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
DECLARE
name,dept VARCHAR2(14);
(1) Points
legal
illegal (*)
2. Examine the following variable declarations:
Which of the following correctly assigns the value 50 to V_RESULT? (1) Points
v_result := v_number * 5;
v_result := 100 / 2;
v_result := ROUND(49.77);
3. After they are declared, variables can be used only once in an application. True or False? (1)
Points
True
False (*)
True (*)
False
legal (*)
illegal
6. Which of the following are required when declaring a variable? (Choose two.) (1) Points
(Choose all correct answers)
NOT NULL
True (*)
False
Which of the following statements correctly assigns the date variable v_today to the value
returned by the format_todays_date function?
(1) Points
v_today := format_todays_date(v_today);
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
1. What are the characteristics of an anonymous block? (Choose two.) (1) Points (Choose all
correct answers)
Unnamed (*)
Exception only
Executable only
3. Which statements are mandatory in a PL/SQL block? (Choose two.) (1) Points (Choose all
correct answers)
DECLARE
BEGIN (*)
EXCEPTION
END; (*)
4. Which lines of code will correctly display the message "Hello World" ? (Choose two.) (1) Points
DBMS_OUTPUT('Hello World');
DBMS_OUTPUT.PUT_LINE('Hello' || 'World');
6. What are the characteristics of a PL/SQL stored subprogram? (Choose two.) (1) Points
(Choose all correct answers)
Named (*)
DECLARE
DBMS_OUTPUT.PUT_LINE(v_date);
END;
(1) Points
True
False (*)
Oracle jDeveloper
SQL*Plus
gSQL*Plus (*)
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello');
(1) Points
10. In a PL/SQL block, which of the following should not be followed by a semicolon? (1) Points
DECLARE (*)
END
Oracle Cdeveloper
Java*Plus
PL/SQL Express
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Trimiteți către Pinterest
Section 1
1. When multiple SQL statements are combined into PL/SQL blocks, performance improves. True
or False? (1) Points
True (*)
False
2. Procedural constructs give you better control of your SQL statements and their execution.
True or False? (1) Points
True (*)
False
3. PL/SQL differs from C and Java in which of the following ways? (Choose two.) (1) Points
(Choose all correct answers)
4. Which of the following can be compiled as a standalone program outside the database? (1)
Points
A program developed in C
6. You can create a Web site application written entirely in PL/SQL. True or False? (1) Points
True (*)
False
Postați pe blog!
Distribuiți pe Twitter
Distribuiți pe Facebook
Section 1
1. In which three ways does PL/SQL extend the SQL programming language? (1) Points
None.
5. Nonprocedural languages allow the programmer to produce a result when a series of steps are
followed. True or False? (1) Points
True
False (*)
Section 4
1. When using a counter to control a FOR loop, which of the following is true ? (1) Points
You must have exactly one counter but it is implicitly declared. (*)
You must have exactly one counter and you must explicitly declare it.
You can have multiple counters, but you need at least one.
You don't need a counter; you can test for anything (for example, whether a BOOLEAN is TRUE
or FALSE).
DECLARE
v_counter NUMBER(4) := 0;
BEGIN
... Line A
...
END;
(1) Points
BEGIN
DBMS_OUTPUT.PUT_LINE (i);
i := i + 1;
END LOOP;
END;
(1) Points
It will display 1, 2, 3.
It will display 2, 3, 4.
It will result in an error because you cannot modify the counter in a FOR loop. (*)
It will result in an error because the counter was not explicitly declared.
4. In a WHILE loop, the statements inside the loop must execute at least once. True or False? (1)
Points
True
False (*)
5. Which of the following blocks produces the same output as this block?
BEGIN
FOR i in 1 .. 3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
(1) Points
DECLARE
i PLS_INTEGER := 0;
BEGIN
DBMS_OUTPUT.PUT_LINE(i);
i := i + 1;
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
i := i + 1;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END; (*)
DECLARE
i PLS_INTEGER := 0;
BEGIN
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
i := i+ 1;
END;
IF condition
THEN statement1
ELSE statement 2;
IF condition
THEN statement1
ELSE statement 2;
END IF;
IF condition;
THEN statement1;
ELSE statement2;
END IF;
ELSE statement2;
IF condition;
THEN statement;
END IF;
IF condition
THEN statement
ENDIF;
a VARCHAR2(6) := NULL;
b VARCHAR2(6) := NULL;
BEGIN
IF a = b THEN
DBMS_OUTPUT.PUT_LINE('EQUAL');
ELSIF a != b THEN
DBMS_OUTPUT.PUT_LINE('UNEQUAL');
ELSE
DBMS_OUTPUT.PUT_LINE('OTHER');
END IF;
END;
(1) Points
UNEQUAL
EQUAL
OTHER (*)
9. What type of control structures are repetition statements that enable you to execute
statements in a PLSQL block repeatedly? (1) Points
IF statements
Loops (*)
CASE expressions
CASE statements
10. What is the correct name for CASE, LOOP, WHILE, and IF-THEN-ELSE structures ? (1) Points
Control structures (*)
Array structures
Memory structures
Cursor structures
DECLARE
v_salary NUMBER(6);
BEGIN
v_result := 'HIGH';
ELSE
v_result := 'LOW';
END IF;
END;
(1) Points
HIGH
LOW (*)
MIDDLE
Null
12. You need to execute a set of statements 10 times, increasing a counter by 1 each time. Which
of the following PL/SQL constructs can do this? (Choose three) (1) Points (Choose all correct
answers)
IF ... THEN ... ELSE
13. Which one of these tasks is best done using a LOOP statement? (1) Points
Calculating and displaying the sum of all integers from 1 to 100 (*)
v_counter := 1;
LOOP
v_counter := v_counter + 1;
END LOOP;
(1) Points
5 (*)
FOR loop
Basic loop
WHILE loop
16. What kind of statement is best suited for displaying the multiplication table for "sixes": 6x1=6,
6x2=12 ... 6x12=72? (1) Points
CASE expression
IF statement
CASE statement
17. The EXIT statement can be located anywhere inside a basic loop. True or False? (1) Points
True (*)
False
18. What will be the value of v_sal_desc after the following code is executed?
DECLARE
v_sal_desc VARCHAR2(10);
BEGIN
CASE
END CASE;
END;
(1) Points
High Paid
Low Paid
Null (*)
19. What value will v_answer contain after the following code is executed?
DECLARE
v_answer VARCHAR2(10);
BEGIN
v_answer :=
CASE
ELSE 'Older'
END CASE;
END;
(1) Points
Exactly 18
Young (*)
Null
Older
20. What will be the value of variable c after the following code is executed?
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := FALSE;
c NUMBER;
BEGIN
c :=
CASE
WHEN a OR b THEN 30
ELSE 40
END CASE;
END;
(1) Points
30 (*)
20
40
10
21. What will be the value of variable c after the following code is executed?
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := NULL;
c NUMBER;
BEGIN
IF a AND b THEN c := 2;
ELSIF a OR b THEN c := 0;
ELSE c := 1;
END IF;
END;
(1) Points
1
Null
0 (*)
22. What will be the value of v_result after the following code is executed?
DECLARE
v_result VARCHAR2(10);
BEGIN
CASE v_grade
END CASE;
END;
(1) Points
Poor
In Between (*)
Null
Very Good
DECLARE
v_outer_count NUMBER := 1;
v_inner_count NUMBER := 1;
BEGIN
LOOP
LOOP
v_inner_count := v_inner_count + 1;
END LOOP;
v_outer_count := v_outer_count + 1;
END LOOP;
END;
(1) Points
The inner loop is exited but the outer loop continues execution. (*)
The outer loop is exited but the inner loop continues execution.
BEGIN
EXIT WHEN j = 7;
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
How many lines of output will be displayed when this code is executed?
(1) Points
35
30 (*)
40
DECLARE
i INTEGER := 0;
BEGIN
i := i+1;
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
(1) Points
EXIT <<outerloop>>
EXIT outerloop
EXIT j_loop
BASIC loops
WHILE loops
FOR loops
27. User TOM has locked a row in the WORKERS table. Now, user DICK wants to open the
following cursor:
CURSOR c IS
What will happen when DICK opens the cursor and tries to fetch rows?
(1) Points
TOM's session is rolled back. DICK's session successfully fetches rows from the cursor.
Both sessions wait for a few seconds; then the system breaks all locks and both sessions raise an
exception.
28. You want to declare a cursor which locks each row fetched by the cursor. Examine the
following code:
DECLARE
CURSOR emp_curs IS
FOR -- Point A
(1) Points
UPDATE;
UPDATE OF salary;
CURSOR c IS
USING(department_id)
WHERE e.last_name='Smith'
FOR UPDATE;
When the cursor is opened and rows are fetched, what is locked?
(1) Points
In the EMPLOYEES table, only the 'Smith' rows are locked. Nothing in the DEPARTMENTS table is
locked.
Each 'Smith' row is locked and Smith's matching rows in DEPARTMENTS are locked. No other
rows are locked in either table. (*)
Nothing is locked because the cursor was not declared with NOWAIT.
30. There are 12 distinct JOB_IDs in the EMPLOYEES table. You need to write some PL.SQL code to
fetch and display all the employees with a specific JOB_ID. The chosen JOB_ID can be different
each time the code is executed.
Write 12 separate PL/SQL blocks, each declaring a cursor with a different JOB_ID in the WHERE
clause.
Write a single PL/SQL block which declares 12 cursors, one for each distinct value of JOB_ID.
Write a single PL/SQL block which declares one cursor using a parameter for the JOB_ID. (*)
Write a single PL/SQL block which uses a cursor to fetch all the employee rows, with an IF
statement to decide which of the fetched rows to display.
31. What is one of the advantages of using parameters with a cursor? (1) Points
You can use a single cursor to fetch a different set of rows each time the cursor is opened. (*)
32. Which of these statements about implicit cursors is NOT true? (1) Points
DECLARE
CURSOR emp_curs IS
FROM employees
ORDER BY salary;
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
...
Which of the following statements successfully opens the cursor and fetches the first row of the
active set?
(1) Points
OPEN emp_curs;
OPEN emp_curs;
OPEN emp_curs;
OPEN emp_curs;
FETCH emp_curs;
OPEN my_curs;
CLOSE my_curs;
(1) Points
C,D,A,B
C,A,D,B (*)
A,C,D,B
C,A,B,D
35. An explicit cursor must always be declared, opened and closed by the PL/SQL programmer.
True or False? (1) Points
True
False (*)
36. The employees table contains 20 rows. What will happen when the following code is
executed?
DECLARE
CURSOR emp_curs IS
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
DBMS_OUTPUT.PUT_LINE(v_job_id);
END LOOP;
CLOSE emp_curs;
END;
(1) Points
21 rows of output will be displayed; the first job_id will be displayed twice.
21 rows of output will be displayed; the last job_id will be displayed twice. (*)
37. For which type of SQL statement must you use an explicit cursor? (1) Points
DML statements that process more than one row.
38. An implicit cursor can be used for a multiple-row SELECT statement. True or False? (1) Points
True
False (*)
v_salary employees.salary%TYPE;
BEGIN
OPEN emp_curs;
CLOSE emp_curs;
END;
(1) Points
The block will fail and an INVALID_CURSOR exception will be raised. (*)
SELECT salary
FROM employees
CURSOR emp_curs IS
SELECT salary
FROM employees
CURSOR emp_dept_curs IS
CURSOR emp_curs IS
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(dept_curs%ROWCOUNT || dept_rec.department_name):
END LOOP;
DBMS_OUTPUT.PUT_LINE(dept_rec.department_id);
END;
(1) Points
The implicitly declared record DEPT_REC cannot be referenced outside the cursor FOR loop. (*)
42. Examine the following code. To display the salary of an employee, what must be coded at
Point A?
DECLARE
BEGIN
END LOOP;
END;
(1) Points
salary
emp_curs.salary
emp_rec.salary (*)
employees.salary
emp_rec.salary IN emp_curs
BEGIN
FOR emp_rec IN
(SELECT * FROM employees WHERE ROWNUM < 10
DBMS_OUTPUT.PUT_LINE(emp_rec%ROWCOUNT || emp_rec.last_name):
END LOOP;
END;
(1) Points
You cannot use FOR UPDATE NOWAIT with a cursor FOR loop using a subquery.
You cannot reference %ROWCOUNT with a cursor FOR loop using a subquery. (*)
44. The DEPARTMENTS table contains four columns. Examine the following code:
DECLARE
CURSOR dept_curs IS
v_dept_rec dept_curs%ROWTYPE;
BEGIN
OPEN dept_curs;
...
(1) Points
The FETCH will fail because the structure of v_dept_rec does not match the structure of the
cursor.
45. Which of the following cursor attributes is set to the total number of rows returned so far? (1)
Points
%ISOPEN
%NOTFOUND
%FOUND
%ROWCOUNT (*)
DECLARE
CURSOR emp_curs IS
v_emp_rec emp_curs%ROWTYPE;
BEGIN
...
...
To display the fetched last name, what should you code at Point A?
(1) Points
v_emp_rec.last_name (*)
v_emp_rec(last_name)
v_emp_rec
last_name
DECLARE
CURSOR emp_curs IS
v_emp_rec emp_curs%ROWTYPE;
A twelfth column is now added to the employees table. Which of the following statements is true?
(1) Points
The block will still work correctly without any changes to the PL/SQL code. (*)
An extra scalar variable must be declared to correspond to the twelfth table column.
48. You want to display all locations, and the departments in each location. Examine the following
code:
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(loc_rec.city);
DBMS_OUTPUT.PUT_LINE(dept_rec.department_name);
END LOOP;
END LOOP;
END;
(1) Points
p_loc_id
location_id
null
loc_rec.location_id (*)
49. Which of the following is a good reason to declare and use multiple cursors in a single PL/SQL
block? (1) Points
Multiple cursors improve performance. They are faster than using a single cursor.
Multiple cursors allow us to fetch rows from two or more related tables without using a JOIN. (*)
Multiple cursors are the only way to use cursors with parameters.
Multiple cursors can be opened many times, while a single cursor can be opened only once.
50. When using multiple nested cursors, what kinds of loops can you use? (1) Points
1. SQL is a common access language for many types of databases, including Ora
(1) Points
True (*)
False
2. PL/SQL extends SQL by including all of the following except: Mark for Re
view
(1) Points
variables
conditional statements
constants
(1) Points
declarative
nondeclarative
procedural (*)
low level
Correct
4. Which PL/SQL block type must return a value? Mark for Review
(1) Points
Anonymous
Function (*)
Procedure
Correct
5. Which of the following tools can NOT be used to develop and test PL/SQL co
(1) Points
Oracle Jdeveloper
Oracle iSQL*Plus
BEGIN
END;
(1) Points
procedure
subroutine
function
anonymous (*)
1. END;
2. EXCEPTION
3. DECLARE
4. BEGIN
(1) Points
2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
8. Which keywords must be included in every PL/SQL block? (Choose two.) Mar
k for Review
(1) Points
END; (*)
EXCEPTION
BEGIN (*)
DBMS_OUTPUT.PUT_LINE
9. Every PL/SQL anonymous block must start with the keyword DECLARE. True or
(1) Points
True
False (*)
Correct
10. PL/SQL can be used not only with an Oracle database, but also with any ki
(1) Points
True
False (*)
11. Which of the following can you use PL/SQL to do? Mark for Review
(1) Points
12. The fact that PL/SQL is portable is a good thing because: Mark for Revi
ew
(1) Points
PL/SQL code can be developed on one platform and deployed on another (*)
Section 2
13. Assignment statements can continue over several lines in PL/SQL. True or
(1) Points
True (*)
False
Correct
14. Variables can be used in the following ways in a PL/SQL block. (Choose tw
To comment code.
DECLARE
(1) Points
Correct.
Correct
16. Variables can be assigned a value in both the Executable and Declaration
(1) Points
True (*)
False
17. What good programming practice would make this code easier to follow?
DECLARE
v_myvar VARCHAR2(20);
BEGIN
DECLARE
v_myvar VARCHAR2(15);
BEGIN
...
END;
END;
(1) Points
Correct
18. Which of the following is an example of using a case convention for good
(1) Points
(1) Points
True (*)
False
20. When an exception occurs within a PL/SQL block, the remaining statements
in the executable section of the block are skipped. True or False? Mark for Re
view
(1) Points
True (*)
False
<<outer_block>>
DECLARE
v_myvar NUMBER;
BEGIN
<<inner_block>>
DECLARE
BEGIN
-- Line A
END;
END;
(1) Points
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 t
he same name
22. Examine the following code. Line A causes an exception. What will be disp
DECLARE
var_a NUMBER := 6;
var_b DATE;
BEGIN
var_a := var_a * 2;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(var_a);
END;
(1) Points
12 (*)
24
<<outer>>
DECLARE
BEGIN
<<inner>> DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(inner.v_myvar);
END;
(1) Points
HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the o
Correct
DECLARE
x VARCHAR2(6) := 'Chang';
BEGIN
DECLARE
x VARCHAR2(12) := 'Susan';
BEGIN
x := x || x;
END;
DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
Susan
Chang (*)
ChangChang
SusanChang
Correct
25. A movie is an example of which category of data type? Mark for Review
(1) Points
Scalar
Composite
Reference
LOB (*)
Incorrect. Refer to Section 2 Lesson 3.
26. What is the data type of the variable V_DEPT_TABLE in the following decla
ration?
DECLARE
(1) Points
Scalar
Composite (*)
LOB
27. Which of these are PL/SQL data types? (Choose three.) Mark for Review
(1) Points
Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)
28. Single row character functions are valid SQL functions in PL/SQL. True or
(1) Points
True (*)
False
Correct
29. Examine the following code. What is the final value of V_MYBOOL ?
DECLARE
v_mynumber NUMBER;
v_mybool BOOLEAN ;
BEGIN
v_mynumber := 6;
END;
(1) Points
True (*)
False
Correct
(1) Points
True
False (*)
Correct
Correct
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= '300';
5 END;
(1) Points
'300'
300 (*)
NULL
Correct
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;
(1) Points
34. Which of the following are disadvantages of implicit data type conversion
(1) Points
If Oracle changes the conversion rules in the future, your code may not wor
35. The implicit data type conversion at Point A may not work correctly. Why
not?
DECLARE
v_mydate DATE;
BEGIN
END;
(1) Points
Correct
(1) Points
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
1. Null
2. False
3. True
4. 0
(1) Points
2 and 3
2, 3 and 4
1, 2 and 3 (*)
1, 2, 3 and 4
Correct
38. If you are using the %TYPE attribute, you can avoid hard coding the: Ma
rk for Review
(1) Points
Data type (*)
Table name
Column name
Constraint
Correct
39. Reserved words can be used as identifiers. True or False? Mark for Revi
ew
(1) Points
True
False (*)
Correct
40. Which of the following are PL/SQL lexical units? (Choose two.) Mark for
Review
(1) Points
Table Columns
Anonymous Blocks
SQL Workshop
41. Which of the following are valid identifiers? (Choose two.) Mark for Revi
ew
(1) Points
Full Name
students_street_address (*)
v_code (*)
#hours
completion_%
Correct
Section 3
BEGIN
VALUES ('NV','Neverland');
COMMIT;
COMMIT;
ROLLBACK;
END;
(1) Points
You have nothing new; the last ROLLBACK undid the INSERTs.
You have the rows added twice; there are four new rows.
BEGIN
SAVEPOINT XA;
VALUES ('NV','Neverland');
COMMIT;
ROLLBACK TO XA;
END;
(1) Points
FROM employees
WHERE employee_id=100;
What is the value of SQL%ISOPEN immediately after the SELECT statement is execut
ed?
(1) Points
True
False (*)
Null
45. There are no employees in Department 77. What will happen when the follow
BEGIN
WHERE department_id=77;
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT)
END;
(1) Points
A NULL is displayed.
An exception is raised because the block does not contain a COMMIT statement
46. Assume there are 5 employees in Department 10. What happens when the foll
UPDATE employees
SET salary=salary*1.1;
(1) Points
No rows are modified because you did not specify "WHERE department_id=10"
he new salary.
Correct
DECLARE
v_holdit employees.last_name%TYPE;
BEGIN ...
(1) Points
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;
Correct
48. Which rows will be deleted from the EMPLOYEES table when the following co
de is executed?
DECLARE
BEGIN
END;
(1) Points
No rows. (*)
49. Which of the following is NOT a good guideline for retrieving data in PL/
(1) Points
Specify the same number of variables in the INTO clause as database columns
50. Which one of these SQL statements can be directly included in a PL/SQL ex
(1) Points
WHERE department_id=60;
(*)
SELECT salary FROM employees
WHERE department_id=60;
1. For which type of SQL statement must you use an explicit cursor?
2. After a cursor has been closed, it can be opened again in the same PL/SQL block. True or False?
True (*)
False
CURSOR emp_curs IS
SELECT salary
FROM employees
CURSOR emp_curs IS
SELECT salary
FROM employees
WHERE last_name LIKE 'S%';
CURSOR emp_dept_curs IS
CURSOR emp_curs IS
4. Which of these constructs can be used to fetch multiple rows from a cursor's active set?
A CASE statement
A basic loop which includes FETCH and EXIT WHEN statements (*)
5. The employees table contains 20 rows. What will happen when the following code is executed?
DECLARE
 CURSOR emp_curs IS
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
DBMS_OUTPUT.PUT_LINE(v_job_id);
END LOOP;
CLOSE emp_curs;
END;
21 rows of output will be displayed; the first job_id will be displayed twice.
21 rows of output will be displayed; the last job_id will be displayed twice. (*)
DECLARE
CURSOR emp_curs IS
v_salary employees.salary%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_salary);
CLOSE emp_curs;
END;
The execution will fail and an error message will be displayed. (*)
v_salary employees.salary%TYPE;
BEGIN
OPEN emp_curs;
CLOSE emp_curs;
END;
The block will fail and an INVALID_CURSOR exception will be raised. (*)
9. In the following code fragment, you want to exit from the outer loop at Line A if v_number = 6.
Which statement would you write on Line A?
<<big_loop>>
<<small_loop>>
DBMS_OUTPUT.PUT_LINE(i);
--Line A
END LOOP;
END LOOP;
10. You want to display multiplication tables for numbers up to 12. The display
1x1=1
1x2=2
.....
1 x 12 = 12
2x1=2
2x2=4
.....
2 x 12 = 24
3x1=3
.....
.....
12 x 12 = 144
Store all the numbers from 1 to 144 in a table, then fetch and display them using a cursor.
Create a function which accepts two numbers as IN parameters and returns their product.
Write an anonymous block which contains 144 calls to DBMS_OUTPUT, each looking like:
DBMS_OUTPUT.PUT_LINE('7 x 9 = 63');
CURSOR emp_curs IS
v_emp_rec emp_curs%ROWTYPE;
BEGIN
...
 ...
To display the fetched last name, what should you code at Point A?
v_emp_rec.last_name (*)
v_emp_rec(last_name)
v_emp_rec
last_name
12. Assume that you have declared a cursor called C_EMP. Which of the following
statements about C_EMP is correct? (Choose two.) (Choose all correct answers)
You can use c_emp%ROWCOUNT to return the number of rows returned by the cursor so far. (*)
CURSOR emp_curs IS
FROM employees;
Which of the following correctly declares a composite record with the same structure as the
cursor?
emp_rec emp_rec%ROWTYPE;
emp_rec emp_curs%TYPE;
emp_rec cursor%ROWTYPE;
14. Which of the following cursor attributes evaluates to TRUE if the cursor is open?
%ISOPEN (*)
%NOTFOUND
%FOUND
%ROWCOUNT
15. Which of the following cursor attributes is set to the total number of rows returned so far?
%ISOPEN
%NOTFOUND
%FOUND
%ROWCOUNT (*)
16. The employees table contains 11 columns. The following block declares a cursor and a record
based on the cursor:
DECLARE
CURSOR emp_curs IS
v_emp_rec emp_curs%ROWTYPE;
A twelfth column is now added to the employees table. Which of the following statements is true?
An extra scalar variable must be declared to correspond to the twelfth table column.
Which of the following do NOT need to be coded explicitly? (Choose three.) (Choose all correct
answers)
END LOOP;
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(dept_curs%ROWCOUNT || dept_rec.department_name);
END LOOP;
DBMS_OUTPUT.PUT_LINE(dept_rec.department_id);
END;
The implicitly declared record DEPT_REC cannot be referenced outside the cursor FOR loop. (*)
19. When using a cursor FOR loop, OPEN, CLOSE and FETCH statements should not be explicitly
coded. True or False?
True (*)
False
20. Examine the following declaration of a cursor with a parameter. What should be coded at
Point A? DECLARE
p_job_id
ST_CLERK'
p_job_id VARCHAR2(25)
job_id VARCHAR2
p_param := 'ABC';
OPEN c_curs(p_param);
v_counter := 1;
LOOP
END LOOP;
v_counter := v_counter + 1;
FOR loop
Basic loop
WHILE loop
24. Which one of these tasks is best done using a LOOP statement?
Calculating and displaying the sum of all integers from 1 to 100 (*)
25. The EXIT statement can be located anywhere inside a basic loop. True or False?
True (*)
False
v_counter := 1;
LOOP
v_counter := v_counter + 1;
END LOOP;
27. What will be the value of v_sal_desc after the following code is executed?
DECLARE
v_sal_desc VARCHAR2(10);
v_sal_desc VARCHAR2(10);
BEGIN
CASE
END CASE;
END;
High Paid
Low Paid
Null
v_grade = 'A' display 'Very Good', if v_grade = 'B' then display 'Good', and so on.
DECLARE
v_grade CHAR(1);
BEGIN
CASE v_grade
IF 'A' THEN
29. What will be the value of v_result after the following code is executed?
DECLARE
v_result VARCHAR2(10);
BEGIN
CASE v_grade
END;
END;
Poor
In Between (*)
Null
Very Good
30. What value will v_answer contain after the following code is executed?
DECLARE
v_answer VARCHAR2(10);
BEGIN
v_answer :=
CASE
ELSE 'Older'
END CASE;
END;
Exactly 18
Young (*)
Null
Older
31. You want to assign a value to v_result which depends on the value of v_grade: if v_grade
DECLARE
v_grade CHAR(1);
v_result VARCHAR2(10);
v_grade CHAR(1);
v_result VARCHAR2(10);
BEGIN
v_result := CASE v_grade
32. You want to declare a cursor which locks each row fetched by the cursor.
DECLARE
CURSOR emp_curs IS
FOR --Point A
UPDATE;
UPDATE OF salary;
UPDATE NOWAIT;
33. User TOM has locked a row in the WORKERS table. Now, user DICK wants to open the
following cursor:
CURSOR c IS
What will happen when DICK opens the cursor and tries to fetch rows?
TOM's session is rolled back. DICK's session successfully fetches rows from the cursor.
DICK's session waits indefinitely.
Both sessions wait for a few seconds; then the system breaks all locks and both sessions raise an
exception.
CURSOR c IS
USING(department_id)
WHERE e.last_name='Smith'
FOR UPDATE;
When the cursor is opened and rows are fetched, what is locked?
In the EMPLOYEES table, only the 'Smith' rows are locked. Nothing in the
Each 'Smith' row is locked and Smith's matching rows in DEPARTMENTS are locked.
Nothing is locked because the cursor was not declared with NOWAIT.
35. Which statement best describes when a FOR loop should be used?
When the controlling condition must be evaluated at the start of each iteration
36. Which statement best describes when a WHILE loop shouild be used?
When repeating a sequence of statements until the controlling condition is no longer true (*)
37. Which of the following blocks produces the same output as this block?
BEGIN
FOR i in 1 .. 3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
DBMS_OUTPUT.PUT_LINE(i);
i := i + 1;
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
i := i + 1;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END; (*)
DECLARE
i PLS_INTEGER := 0;
BEGIN
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
i := i+ 1;
END;
DECLARE
v_counter NUMBER(4) := 0;
BEGIN
... Line A
END;
39. In a FOR loop, an implicitly declared counter automatically increases or decreases with each
iteration. True or False?
True (*)
False
40. In a WHILE loop, the statements inside the loop must execute at least once. True or False?
True
False (*)
IF condition;
THEN statement;
END IF;
IF condition
THEN statement
ENDIF;
42. You need to execute a set of statements 10 times, increasing a counter by 1 each
time. Which of the following PL/SQL constructs can do this? (Choose three) (Choose all correct
answers)
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := FALSE;
c BOOLEAN := TRUE;
d BOOLEAN := FALSE;
BEGIN
END IF;
NULL
won'
lost' (*)
False
IF condition
THEN statement1
ELSE statement 2;
IF condition
THEN statement1
ELSE statement 2;
END IF;
IF condition;
THEN statement1;
ELSE statement2;
END IF;
IF condition THEN statement1;
ELSE statement2;
45. You want to display all locations, and the departments in each location. Examine the following
code:
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(loc_rec.city);
DBMS_OUTPUT.PUT_LINE(dept_rec.department_name);
END LOOP;
END LOOP;
END;
p_loc_id
location_id
null
loc_rec.location_id (*)
46. Which of the following is a good reason to declare and use multiple cursors in a single PL/SQL
block?
Multiple cursors improve performance. They are faster than using a single cursor.
Multiple cursors use less memory than a single cursor.
Multiple cursors allow us to fetch rows from two or more related tables without using a
JOIN. (*)
Multiple cursors are the only way to use cursors with parameters.
Multiple cursors can be opened many times, while a single cursor can be opened only once.
47. When using multiple nested cursors, what kinds of loops can you use?
1. What statement allows you to exit the outer loop at Point A in the following block?
DECLARE
BEGIN
...
...
... -- Point A
...
END LOOP;
...
...
END LOOP;
END;
(1) Points
2. Which one of these statements about using nested loops is true? (1) Points
The outer loop must be labelled, but the inner loop need not be labelled
The outer loop must be labelled if you want to exit the outer loop from within the inner loop (*)
DECLARE
x NUMBER(6) := 0 ;
BEGIN
x := x+1 ;
END LOOP;
END LOOP;
DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
5
10
15
50 (*)
4. When the following code is executed, how many lines of output will be displayed?
BEGIN
END LOOP;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
(1) Points
80
45 (*)
14
41
BEGIN
-- Point A
END LOOP;
END LOOP;
END;
(1) Points
LOOP
DECLARE
v_blue NUMBER(3) := 0;
v_red NUMBER(3) := 0;
BEGIN
v_blue := v_blue + 1;
v_red := v_red + 1;
-- Line A
END;
What should you code at Line A to exit from the outer loop?
(1) Points
EXIT;
EXIT red;
EXIT <<blue>>;
DECLARE
(department_id departments.department_id%TYPE,
department_name departments.department_name%TYPE);
(first_name employees.first_name%TYPE,
last_name employees.last_name%TYPE),
dept_info dept_info_type);
v_emp_dept_rec emp_dept_type;
one
two
three
four (*)
Which of the following methods can be used to reference elements of an INDEX BY table? (Choose
three.)
EXISTS (*)
FIRST (*)
PREVIOUS
DROP
COUNT (*)
BEGIN
FOR emp_rec IN
DBMS_OUTPUT.PUT_LINE(emp_rec%ROWCOUNT || emp_rec.last_name):
END LOOP;
END;
You cannot use FOR UPDATE NOWAIT with a cursor FOR loop using a subquery.
You cannot reference %ROWCOUNT with a cursor FOR loop using a subquery. (*)
Which of the following is NOT a valid cursor FOR loop with a subquery?
FOR emp_rec IN
FOR emp_rec IN
FOR emp_rec IN
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
CURSOR bigemp_cur IS
BEGIN
DBMS_OUTPUT.PUT_LINE (dept_rec.department_name);
IF emp_rec.department_id=dept_rec.department_id
END IF;
END LOOP;
END LOOP;
END;
It reads 1000 employee rows every time BIGEMP_CUR is OPENed, and then ignores 990
of them. (*)
It is using cursor FOR loops, which are less efficient than OPENing and CLOSEing the
cursors explicitly.
Which of the following is NOT allowed when using multiple cursors with parameters?
DECLARE
c_rec c%ROWTYPE;
BEGIN
OPEN c;
IF i = 6 THEN
WHERE CURRENT OF c;
END IF;
END LOOP;
CLOSE c;
END;
Which employee row or rows will be updated when this block is executed?
The block will not compile because the cursor should have been declared .... FOR UPDATE
WAIT 5;
None of these.
No rows will be updated because you locked the rows when the cursor was opened.
CURSOR c IS
USING(department_id)
WHERE e.last_name='Smith'
FOR UPDATE;
When the cursor is opened and rows are fetched, what is locked?
The whole EMPLOYEES and DEPARTMENTS tables are locked.
Each 'Smith' row is locked and Smith's matching rows in DEPARTMENTS are locked. No
other rows are locked in either table. (*)
Nothing is locked because the cursor was not declared with NOWAIT.
In the EMPLOYEES table, only the 'Smith' rows are locked. Nothing in the DEPARTMENTS
table is locked.
You need to SELECT more than one row from a table. (*)
You need to UPDATE more than one row in a table.
DECLARE
v_dept_name departments.department_name%TYPE;
BEGIN
OPEN dept_curs;
LOOP
DBMS_OUTPUT.PUT_LINE(v_dept_name);
CLOSE dept_curs;
END LOOP;
END;
The EXIT WHEN ... statement should be coded outside the loop.
DECLARE
CURSOR emp_curs IS
v_emp_rec emp_curs%ROWTYPE;
BEGIN
...
...
To display the fetched last name, what should you code at Point A?
v_emp_rec
v_emp_rec(last_name)
None of these.
v_emp_rec.last_name (*)
last_name
You can reference explicit cursor attributes directly in a SQL statement. True or False?
True
False (*)
Which of the following statements about the %ISOPEN cursor attribute is true?
You can issue the %ISOPEN cursor attribute only when a cursor is open.
You can issue the %ISOPEN cursor attribute only when more than one record is returned.
You can issue the %ISOPEN cursor attribute when a cursor is open or closed. (*)
What is missing from the following cursor declaration?
CURSOR emp_curs
IS
A parameter is missing. The parameter should be coded as: (p_loc_id NUMBER) (*)
The declaration is invalid. You cannot reference a cursor parameter in a WHERE clause.
DECLARE
v_emp_rec emp_curs%ROWTYPE;
v_deptid NUMBER(4) := 50;
BEGIN
....
You want to open the cursor, passing value 50 to the parameter. Which of the following are
correct at Point A?
100 / 2
v_deptid
50
Examine the following code. Why does this exception handler not follow good practice guidelines?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
END;
The exception handler should test for the named exception NO_DATA_FOUND. (*)
Which of the following is NOT an advantage of including an exception handler in a PL/SQL block?
Code is more readable because error-handling routines can be written in the same block
in which the error occurred
Prevents errors from occurring (*)
EXCEPTION
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END;
TRUE (*)
FALSE
No employees are in department_id 99. What output will be displayed when the following code is
executed?
DECLARE
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
IF v_count = 0 THEN
RAISE NO_DATA_FOUND;
END IF;
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Department 99 is empty');
END;
The block will fail because you cannot explicitly RAISE a predefined Oracle Server error
such as NO_DATA_FOUND
No employees found
User-defined exceptions must be declared explicitly by the programmer, but then are raised
automatically by the Oracle Server. True or False?
TRUE
FALSE (*)
VARCHAR2
NUMBER
None of these.
EXCEPTION (*)
BOOLEAN
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
END;
(Assume that err_log_table has been created with suitable columns and datatypes.)
TRUE
FALSE (*)
A PL/SQL block executes and an Oracle Server exception is raised. Which of the following contains
the text message associated with the exception?
SQLERRM (*)
SQL%MESSAGE
SQL_MESSAGE_TEXT
SQLCODE
Which of these exceptions would need to be raised explicitly by the PL/SQL programmer?
OTHERS
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
BEGIN
RAISE e_excep2;
END;
END;
It will fail to compile because you cannot declare more than one exception in the same
block.
It will compile successfully and return an unhandled e_excep2 to the calling environment.
(*)
It will fail to compile because you cannot have a subblock inside an exception section.
<< outer>>
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 25;
DECLARE
BEGIN
outer.v_myvar := 30;
v_myvar := v_myvar / 0;
outer.v_myvar := 35;
END;
v_myvar := 40;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(v_myvar);
END;
40
35
30 (*)
25
100
The following are the steps involved in creating, and later modifying and re-creating, a PL/SQL
procedure in Application Express. Which step is missing?
A programmer wants to create a PL/SQL procedure named EMP_PROC. What will happen when
the following code is executed?
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
END;
The statement will raise a NO_DATA_FOUND exception because employee_id 999 does
not exist.
The statement will fail because the procedure does not have any parameters.
The statement will fail because you cannot declare variables such as v_salary inside a
procedure.
The statement will fail because the last line of code should be END emp_proc;
B. A calling application
C. A SELECT statement
A only
A and B
B and C
A, B, and D (*)
A and C
An actual parameter is declared in the calling environment, not in the called procedure.
An actual parameter can have a Boolean datatype.
The datatypes of an actual parameter and its formal parameter must be compatible.
Which one of the following statements about formal and actual parameters is true?
A formal parameter is declared within the called procedure, while an actual parameter is
declared in the calling environment. (*)
Named
Positional (*)
None of these.
Procedure SOMEPROC has five parameters named A, B, C, D, E in that order. The procedure was
called as follows:
SOMEPROC(10,20,30,D=>50,E=>60);
Positional (*)
A combination of positionally and named
Defaulted
Named
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?
None of these
DROP PROGRAM mehmet.get_emp
Which dictionary view will list all the PL/SQL subprograms in your schema?
user_subprograms
user_objects (*)
user_dependencies
user_procedures
user_source
IS
PRAGMA AUTONOMOUS_TRANSACTION
BEGIN
COMMIT;
END log_usage;
The subprogram will fail because the PRAGMA statement must be before IS.
The subprogram will fail because it is missing AUTHID CURRENT_USER before IS.
Procedure GET_EMPS includes a SELECT…FROM EMPLOYEES. The procedure was created using
Invoker's Rights. Which of the following statements are true? (Choose three.)
The user who executes the procedure needs EXECUTE privilege on the procedure. (*)
The user who executes the procedure needs SELECT privilege on EMPLOYEES. (*)
You want to allow user JOE to query the CD_DETAILS table in your schema. Which command
should you use?
USERC needs to execute UserB's procedure. What privileges are needed for this to work correctly?
(Choose two.)
False (*)
(p_emp_id IN employees.employee_id%TYPE)
DECLARE
v_mynum NUMBER(6,2);
v_mydate DATE;
BEGIN
... Line A
END;
find_sal(100,v_mynum);
v_mydate := find_sal(100);
find_sal(v_mynum,100);
B Write the code containing the CREATE or REPLACE FUNCTION followed by the function code
B,C,E,F,D,A
D,B,E,F,A,C
A,B,E,F,D,C
B,E,F,D,A,C (*)
JOHN and FRED are database users. JOHN grants SELECT privilege to FRED on three of his (JOHN's)
tables. Which Dictionary view should FRED query to see the names of JOHN's three tables?
DICTIONARY
DBA_TABLES
ALL_TABLES (*)
FRED_TABLES
USER_TABLES
You want to find out how many Dictionary views will list objects in your schema (but not in other
users' schemas). Which of the following queries should you use to do this?
SELECT COUNT(*)
FROM DBA_OBJECTS
WHERE OWNER='USER';
SELECT COUNT(*)
FROM DICTIONARY
(*)
SELECT COUNT(*)
FROM DICTIONARY
SELECT COUNT(*)
FROM USER_DICTIONARY;
SELECT COUNT(*)
FROM DICTIONARY;
When creating a user-defined function that will be called from a SQL statement, the size of the
returned values may be up to the size of any PL/SQL data type. True or False?
True
False (*)
Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE FUNCTION double_sal
(p_salary IN employees.salary%TYPE) RETURN NUMBER IS BEGIN RETURN(p_salary * 2); END;
Which of the following calls to DOUBLE_SAL will NOT work?
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
COMMIT;
An OUT parameter
Section 5
DECLARE
(department_id departments.department_id%TYPE,
department_name departments.department_name%TYPE);
(first_name employees.first_name%TYPE,
last_name employees.last_name%TYPE),
dept_info dept_info_type);
v_emp_dept_rec emp_dept_type;
(1) Points
four (*)
one
three
two
(1) Points
True
False (*)
Section 6
3. Which of the following explicit cursor attributes evaluates to TRUE if the most recent
(1) Points
%FOUND (*)
%NOTFOUND
%ROWCOUNT
%ROWTYPE
Correct
4. Which of the following statements about the %ISOPEN cursor attribute is true?
(1) Points
You can issue the %ISOPEN cursor attribute only when more than one record is
returned.
You can issue the %ISOPEN cursor attribute only when a cursor is open.
You can issue the %ISOPEN cursor attribute when a cursor is open or closed. (*)
Correct
5. Assume that you have declared a cursor called C_EMP. Which of the following
You can use c_emp%ROWCOUNT to return the number of rows returned by the
Correct
DECLARE
department_id = p_dept_id;
BEGIN
departments) LOOP
DBMS_OUTPUT.PUT_LINE(dept_rec.departm
ent_name);
FOR emp_rec IN
emp_curs(dept_rec.department_id) LOOP
DBMS_OUTPUT.PUT_LINE(emp_rec.last_na
me);
END LOOP;
END LOOP;
END;
Mark for
Review
(1) Points
(*)
Correct
cursor as:
CURSOR dept_curs IS
ORDER BY department_id;
(Choose two).
Mark for
Review
(1) Points
departments.department_id;
employees;
departments.department_id%TYPE) IS
Correct
= 'Grant';
Mark for
Review
(1) Points
one 'Grant'.
Correct
Review
(1) Points
programmer. (*)
by Oracle.
Correct
Review
(1) Points
one row
statements
Correct
DECLARE
v_last_name
employees.last_name%TYPE;
BEGIN
OPEN emp_curs;
LOOP -- Point A
Mark for
Review
(1) Points
DBMS_OUTPUT.PUT_LINE(v_last_na
me);
END LOOP;
CLOSE emp_curs;
END;
displayed?
twice)
Smith (*)
Jones
Correct
Review
(1) Points
%NOTFOUND. (*)
tables.
declaration section.
Correct
Mark for
Review
(1) Points
True (*)
False
6 Lesson 3.
DECLARE
departments;
BEGIN
DBMS_OUTPUT.PUT_LINE(dept_curs%ROWC
OUNT || dept_rec.department_name):
END LOOP;
DBMS_OUTPUT.PUT_LINE(dept_rec.department
_id);
END;
Mark for
Review
(1) Points
successfully.
loop. (*)
FOR loop.
Correct
CURSOR c IS
d.department_name
USING(department_id)
WHERE e.last_name='Smith'
FOR UPDATE;
When the cursor is opened and rows are fetched,
what is locked?
Mark for
Review
(1) Points
table is locked.
Correct
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 --
; What should
you code at
Line A?
(1) Points
FOR LOCK
Correct
CURSOR emp_curs
(p_dept_id employees.department_id%TYPE,
p_job_id employees.job_id%TYPE) IS
(1) Points
OPEN emp_curs(20);
Correct
18. Using parameters with a cursor, you can open and close the cursor
several times in a block, returning a different active set each time. True
or False?
(1) Points
True (*)
False
Section 7
19. How would you trap Oracle Server exception ORA-01403: no data
(1) Points
Correct
20. Which of the following are examples of predefined Oracle Server errors?
ZERO_DIVIDE (*)
TOO_MANY_ROWS (*)
NO_DATA_FOUND (*)
E_INSERT_EXCEP
OTHERS
Correct
DECLARE
v_last_name
employees.last_name%TYPE;
BEGIN
v_number := v_number / 0;
EXCEPTION
DBMS_OUTPUT.PUT_LINE('No
DBMS_OUTPUT.PUT_LINE('Atte
DBMS_OUTPUT.PUT_LINE('An
error occurred');
END;
Mark for
Review
(1) Points
An error occurred
Correct
EXCEPTION
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END;
Mark for
Review
(1) Points
TRUE (*)
FALSE
Correct
exception can occur at the same time. True or False? Mark for
Review
(1) Points
TRUE
FALSE (*)
Correct
Review
(1) Points
Correct
code is executed?
DECLARE
e_my_excep EXCEPTION;
BEGIN
BEGIN
RAISE e_my_excep;
END IF;
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Message 1');
RAISE e_my_excep;
DBMS_OUTPUT.PUT_LINE('Message 2');
END;
DBMS_OUTPUT.PUT_LINE('Message 3');
EXCEPTION
Mark for
Review
(1) Points
DBMS_OUTPUT.PUT_LINE('Message 4');
END;
Message 1
Message 4
(*)
Message 1
Message 2
Message 1
Message 3
Message 4
Message 1
Message 3
7 Lesson 3.
26.Department-id 99 does not exist.
DECLARE
v_deptname
departments.department_name%TYP
E;
BEGIN
v_deptname
department_id = 99;
EXCEPTION
RAISE_APPLICATION_ERROR(-
END;
Mark for
Review
(1) Points
None of these.
Correct
Mark for
Review
(1) Points
section.
NO_DATA_FOUND.
Correct
BEGIN
DECLARE
e_constraint_violation EXCEPTION;
PRAGMA
EXCEPTION_INIT(e_constraint_violation, -2292);
BEGIN
DBMS_OUTPUT.PUT_LINE('Inner block
message');
END;
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Outer block
message');
END;
Mark for
Review
(1) Points
PRAGMA EXCEPTION_INIT(-2292,
e_constraint_violation);
Correct
executed?
DECLARE
e_outer_excep EXCEPTION;
BEGIN
DECLARE
e_inner_excep EXCEPTION;
BEGIN
RAISE e_outer_excep;
END;
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Outer raised');
DBMS_OUTPUT.PUT_LINE('Inner raised');
END;
Mark for
Review
(1) Points
Correct
Section 8
Mark for
Review
(1) Points
(v_num)
(v_num NUMBER(4,2))
(v_num NUMBER(6,2))
Correct
31. Procedure
TESTPROC
accepts
one
parameter
P1, whose
value is up
to 1000
characters
in length.
Which one
of the
following
declares
this
parameter
correctly?
(1) Points
p1 VARCHAR2
IS
BEGIN ....
(p1 VARCHAR2)
IS
BEGIN ....
(*)
IS
p1 VARCHAR2(100);
BEGIN ....
CREATE PROCEDURE testproc
(p1 VARCHAR2(100) )
IS
BEGIN ....
DECLARE
p1 VARCHAR2(100);
BEGIN ....
Correct
(A IN NUMBER := 50,
B IN NUMBER,
IS .....
Mark for
Review
(1) Points
defproc;
Correct
myproc('Smith',100,5000);
Mark for
Review
(1) Points
Positional (*)
Named
None of these.
34. A nested subprogram can be called from the main procedure or from the
Review
(1) Points
True
False (*)
Correct
35. Which of the following keywords MUST be included in every PL/SQL procedure
Review
(1) Points
DECLARE
BEGIN (*)
EXCEPTION
END (*)
REPLACE
following are
characteristics
of PL/SQL
stored
procedures?
(Choose
three.)
(1) Points
Correct
Section 9
(p_emp_id IN employees.employee_id%TYPE)
DECLARE
v_mynum NUMBER(6,2);
v_mydate DATE;
BEGIN
... Line A
END;
Mark for
Review
(1) Points
find_sal(v_mynum,100);
find_sal(100,v_mynum);
v_mydate := find_sal(100);
Correct
RETURN NUMBER
IS
BEGIN
END;
Mark for
Review
(1) Points
An error message will be displayed because you cannot nest userdefined functions.
11
17 (*)
66
23
Correct
39. A function must have at least one IN parameter, and must return exactly
Review
(1) Points
True
False (*)
Correct
40. Which of the following will tell you how many functions you own?
Mark for
Review
(1) Points
OBJECT_TYPE='FUNCTION'; (*)
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?
Mark for
Review
(1) Points
USER_TABLES
ALL_TABLES (*)
DBA_TABLES
None of these.
USER_TAB_COLUMNS
Correct
42. User SALLY's schema contains a NEWEMP table. Sally uses Invoker's rights
other privileges. What will happen when Curly executes the procedure?
Mark for
Review
(1) Points
The procedure will fail because Curly does not have the EXECUTE ANY
The procedure will fail because Curly does not have SELECT privilege
on NEWEMP.
Correct
PROCEDURE at_proc IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
UPDATE ...
INSERT ...
END at_proc;
Mark for
Review
(1) Points
44. Which dictionary view will list all the PL/SQL subprograms in your schema?
Mark for
Review
(1) Points
user_objects (*)
user_procedures
user_dependencies
user_source
user_subprograms
Correct
IS BEGIN
child1;
child2;
EXCEPTION
END parent;
Mark for
Review
(1) Points
exception handler.
CHILD1 ends abruptly; PARENT handles the exception and then ends;
execute.
unhandled exception.
CHILD2 executes.
Correct
function called
SEL_PROC
which includes
the statement:
SELECT ...
FROM
usera.employees
...;
USERC needs to
execute UserB's
procedure. What
privileges are
to work
correctly?
(Choose two.)
Mark for
Review
(1) Points
Correct
Mark for
Review
(1) Points
CREATE
SELECT
UPDATE (*)
DELETE
DROP
48. A benefit of user-defined functions is that the function can accept any
Review
(1) Points
True
False (*)
Correct
49. Which of the following is NOT a legal location for a function call in a SQL
Review
(1) Points
Correct
50. 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? Mark for
Review
(1) Points
An OUT parameter
RETURN BOOLEAN
COMMIT;
Correct
1. Which of these is NOT a valid cursor declaration?
(1) Points
CURSOR emp_curs IS
SELECT salary
FROM employees
CURSOR emp_dept_curs IS
CURSOR emp_curs IS
CURSOR emp_curs IS
SELECT salary
FROM employees
Correct
v_salary employees.salary%TYPE;
BEGIN
OPEN emp_curs;
CLOSE emp_curs;
END;
Mark for Review
(1) Points
The block will fail and an INVALID_CURSOR exception will be raised. (*)
Correct
DECLARE
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
OPEN emp_curs;
CLOSE emp_curs;
END;
(1) Points
When FETCHing more than one row, you MUST use a loop.
Correct
4. After a cursor has been closed, it can be opened again in the same
(1) Points
TRUE (*)
FALSE
Correct
DECLARE
CURSOR emp_curs IS
v_emp_rec emp_curs%ROWTYPE;
(1) Points
column.
The block will still work correctly without any changes to the PL/SQL
code. (*)
Correct
6. How must you reference one field which is part of a PL/SQL record?
(1) Points
It cannot be done.
field_name.record_name
record_name.field_name (*)
field_name OF record_name
record_name(field_name)
Correct
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?
(1) Points
Correct
CURSOR c IS
USING(department_id)
WHERE e.last_name='Smith'
FOR UPDATE;
When the cursor is opened and rows are fetched, what is locked?
(1) Points
In the EMPLOYEES table, only the 'Smith' rows are locked. Nothing in the
Nothing is locked because the cursor was not declared with NOWAIT.
Each 'Smith' row is locked and Smith's matching rows in DEPARTMENTS are
Correct
9. If the rows you attempt to reserve using FOR UPDATE have already been
locked by another session and you use the NOWAIT option, what is the
outcome?
(1) Points
Your rows will override the other user's lock and your block will execute
successfully.
The server will wait until the locks have been released by the other user.
10. Which of the following is NOT allowed when using multiple cursors with
parameters?
(1) Points
Correct
Previous
11. You want to produce a report which displays each department and
CURSOR dept_curs IS
ORDER BY department_id;
(1) Points
p_dept_id;(*)
departments.department_id;
Correct
12. What is the DISadvantage of using a cursor FOR loop with a subquery?
(1) Points
Correct
13. Which one of the following is a valid cursor FOR loop with a subquery?
(1) Points
LOOP ...
LOOP ...
None of these.
LOOP ...
Correct
CURSOR emp_curs
IS
(1) Points
NUMBER) (*)
WHERE clause.
NUMBER)
Correct
15. There are 12 distinct JOB_IDs in the EMPLOYEES table. You need to
write some PL/SQL code to fetch and display all the employees with a
specific JOB_ID. The chosen JOB_ID can be different each time the code is
executed.
(1) Points
Write a single PL/SQL block which declares one cursor using a parameter for
the JOB_ID. (*)
Write a single PL/SQL block which uses a cursor to fetch all the employee
Write a single PL/SQL block which declares 12 cursors, one for each distinct
value of JOB_ID.
Correct
Previous
DECLARE
c_rec c%ROWTYPE;
BEGIN
OPEN c;
IF i = 6 THEN
WHERE CURRENT OF c;
END IF;
END LOOP;
CLOSE c;
END;
Which employee row or rows will be updated when this block is executed?
(1) Points
None of these.
No rows will be updated because you locked the rows when the cursor was
opened.
The block will not compile because the cursor should have been declared ....
--Block A
DECLARE
CURSOR emp_cursor IS
FROM employees
WHERE department_id = 80
--Block B
DECLARE
CURSOR emp_cursor IS
FROM employees
WHERE department_id = 80
NOWAIT;
(1) Points
In Block A, the program waits indefinitely until locked rows are available. In
work. (*)
In Block A, the program waits indefinitely until locked rows are available. In
other work.
3. 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
FROM employees
(1) Points
FOR LOCK
Correct
4. Which of the following is NOT allowed when using multiple cursors with
parameters?
(1) Points
Correct
DECLARE
BEGIN
FOR dept_rec IN (SELECT * FROM departments) LOOP
DBMS_OUTPUT.PUT_LINE(dept_rec.department_name);
DBMS_OUTPUT.PUT_LINE(emp_rec.last_name);
END LOOP;
END LOOP;
END;
(1) Points
You cannot use two different kinds of loops in a single PL/SQL block.
Nothing is wrong. The block will execute successfully and display all
Correct
(1) Points
Correct
(1) Points
Correct
8. Assume that you have declared a cursor called C_EMP. Which of the
(1) Points
You can use c_emp%ROWCOUNT to return the number of rows returned by the cursor so far.(*)
Correct
open?
(1) Points
%NOTFOUND
%FOUND
%ISOPEN (*)
%ROWCOUNT
Correct
10. Using parameters with a cursor, you can open and close the cursor
several times in a block, returning a different active set each time. True or
False?
Mark for Review
(1) Points
True (*)
False
Correct
Previous
11. You want to use explicit cursors to fetch and display all the countries in a
want to use a different region each time the cursor is opened. How many
(1) Points
Correct
12. The employees table contains 20 rows. What will happen when the
DECLARE
CURSOR emp_curs IS
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
DBMS_OUTPUT.PUT_LINE(v_job_id);
EXIT WHEN emp_curs%NOTFOUND;
END LOOP;
CLOSE emp_curs;
END;
(1) Points
21 rows of output will be displayed; the first job_id will be displayed twice.
twice. (*)
Correct
13. Which of the following best describes the difference between implicit and
explicit cursors?
(1) Points
Implicit cursors store rows on disk, while explicit cursors store rows in
memory.
Implicit cursor are named by the PL/SQL programmer, while explicit cursors
Implicit cursors are used for SELECT statements, while explicit cursors are
Correct
(1) Points
statements.
Correct
15. After a cursor has been closed, it can be opened again in the same
(1) Points
TRUE (*)
FALSE
Correct
Previous
Section 1
1. Which of the following statements about PL/SQL and SQL is true? (1) Points
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. (*)
2. Errors are handled in the Exception part of the PL/SQL block. True or False? (1) Points
True (*)
False
Section 2
3. Which of the following are valid assignment statements? (Choose two.) (1) Points (Choose all
correct answers)
v_string = 'Hello';
v_string := Hello;
v_date := 28-DEC-06;
4. Which of the following are valid identifiers? (Choose two.) (1) Points (Choose all correct
answers)
Full Name
students_street_address (*)
v_code (*)
#hours
completion_%
Scalar
Composite
Reference
LOB (*)
6. If you are using the %TYPE attribute, you can avoid hard coding the: (1) Points
Table name
Column name
Constraint
7. When an exception occurs within a PL/SQL block, the remaining statements in the executable
section of the
True (*)
False
Section 3
8. You declare an implicit cursor in the DECLARE section of a PL/SQL block. True or False? (1) Points
True
False (*)
9. 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;
BEGIN
FROM employees
END;
(1) Points
True
False (*)
10. What keyword goes at the beginning of the following SQL statement?
USING all_objects b
ON (a.object_id = b.object_id)
(1) Points
INSERT
UPDATE
DELETE
MERGE (*)
Section 4
v_counter := 1;
LOOP
v_counter := v_counter + 1;
END LOOP;
What is the value of V_COUNTER after the loop is finished?
(1) Points
5 (*)
12. What will be the value of variable c after the following code is executed?
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := NULL;
c NUMBER;
BEGIN
IF a AND b THEN c := 2;
ELSIF a OR b THEN c := 0;
ELSE c := 1;
END IF;
END;
(1) Points
Null
0 (*)
13. When coding two nested loops, both loops must be of the same type. For example, you cannot
code a FOR loop inside a WHILE loop. True or False? (1) Points
True
False (*)
14. What type of control structures are repetition statements that enable you to execute
statements in a PLSQL block repeatedly? (1) Points
IF statements
Loops (*)
CASE expressions
CASE statements
15. Which statement best describes when a FOR loop should be used? (1) Points
When the controlling condition must be evaluated at the start of each iteration
Section 5
16. The employees table contains 20 rows. What will happen when the following code is
executed?
DECLARE
CURSOR emp_curs IS
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
DBMS_OUTPUT.PUT_LINE(v_job_id);
EXIT WHEN emp_curs%NOTFOUND;
END LOOP;
CLOSE emp_curs;
END;
(1) Points
21 rows of output will be displayed; the first job_id will be displayed twice.
21 rows of output will be displayed; the last job_id will be displayed twice. (*)
(1) Points
p_param := 'ABC';
OPEN c_curs(p_param);
18. You want to display each row from the DEPARTMENTS table, and immediately underneath it, a
list of all EMPLOYEES in that department. Which of the following is a good way to do this? (1)
Points
DEPARTMENT_ID. (*)
Write a SELECT statement which JOINs the two tables, and use CONNECT BY PRIOR and LEVEL to
display the rows in the correct order.
Change the physical model so that all employee and department data is in a single table.
Which of the following is NOT a valid cursor FOR loop with a subquery? (1) Points
FOR emp_rec IN
FOR emp_rec IN
FOR emp_rec IN
FOR emp_rec IN
CURSOR emp_curs IS
FROM employees;
Which of the following correctly declares a composite record with the same structure as the
cursor?
(1) Points
emp_rec emp_rec%ROWTYPE;
emp_rec emp_curs%TYPE;
emp_rec cursor%ROWTYPE;
Section 5
21. User MARY has locked a row of the EMPLOYEES table. Now, user SAEED tries to open the
following cursor:
CURSOR c IS
What will happen when SAEED's session tries to fetch the row that MARY has locked?
(1) Points
SAEED's session successfully fetches the first 5 rows and then waits indefinitely to fetch the 6th
row.
SAEED's session waits for 5 seconds, and then raises an exception if MARY has not unlocked the
row. (*)
SAEED's session waits for 5 seconds, then SAEED is disconnected from the database.
SAEED's session waits for 5 seconds, then MARY's session is rolled back.
SAEED's session waits for 5 minutes, and then raises an exception if MARY has not unlocked the
row.
Section 6
22. Which of the following statements could cause a DDL trigger to fire? (1) Points
23. Examine the following code. To create a row trigger, what code should be included at Line A?
-- Line A
BEGIN ...
(1) Points
ON EACH ROW
ON EVERY ROW
Section 7
24. 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
DBMS_OUTPUT.PUT_LINE('B');
END;
DBMS_OUTPUT.PUT_LINE('C');
EXCEPTION
DBMS_OUTPUT.PUT_LINE('D');
END;
(1) Points
D(*)
25. Examine the following code. Why does the exception handler not follow good practice
guidelines?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
EXCEPTION
END;
(1) Points
The exception handler should test for the named exception NO_DATA_FOUND. (*)
26. Which of the following will successfully return a user-defined error message? (1) Points
RAISE_APPLICATION_ERROR('Error Raised',-22001);
RAISE_APPLICATION_ERROR(-22001,'Error Raised');
RAISE_APPLICATION_ERROR('Error Raised',-20257);
27. Examine the following code. What message or messages will be displayed when this code is
executed?
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
v_number := v_number / 0;
EXCEPTION
END;
(1) Points
An error occurred
Section 8
28. A PL/SQL stored procedure can accept one or more input parameters and can return one or
more output values to the calling environment. True or False? (1) Points
True (*)
False
29. You want to create a procedure named SOMEPROC which accepts a single parameter named
SOMEPARM. The parameter can be up to 100 characters long. Which of the following is correct
syntax to do this? (1) Points
CREATE PROCEDURE someproc
(someparm varchar2)
IS
BEGIN ...(*)
(someparm varchar2(100) )
IS
BEGIN...
IS
(someparm VARCHAR2;)
BEGIN...
someparm varchar2(100);
IS
BEGIN...
(someparm 100)
IS
BEGIN ...
30. Suppose you set up a parameter with an explicit OUT mode. What is true about that
parameter? (1) Points
It must have a DEFAULT value.
It acts like a constant (its value cannot be changed inside the subprogram).
Section 9
31. Which Data Dictionary view can be used to display the detailed code of a procedure in your
schema? (1) Points
USER_PROCEDURES
USER_OBJECTS
USER_SOURCE (*)
USER_SUBPROGRAMS
32. A function must have at least one IN parameter, and must return exactly one value. (1) Points
True
False (*)
33. How do you specify that you want a procedure MYPROCA to use "Definer's Rights"? (1) Points
Definer's Rights are the default, therefore no extra code or commands are needed. (*)
34. Which of the following is a legal location for a function call in a SQL statement? (Choose 3) (1)
Points
Section 10
35. Which of the following will display the detailed code of the subprograms in package DEPTPACK
in your schema ? (1) Points
ORDER BY line;
ORDER BY line;(*)
ORDER BY line;
SELECT text FROM USER_SOURCE
ORDER BY line;
36. A public function in a package is invoked from within a SQL statement. The function's code can
include a COMMIT statement. True or False? (1) Points
True
False (*)
37. What is wrong with the following syntax for creating a package specification?
FUNCTION func2;
END mypack;
(1) Points
The first line should be: CREATE OR REPLACE PACKAGE SPECIFICATION mypack IS
Section 11
38. DBMS_OUTPUT.PUT_LINE can be invoked from inside a private packaged function. True or
False? (1) Points
True (*)
False
g_myvar NUMBER;
multipack.g_myvar := 45;
User HAZEL now connects to the database. Both users immediately execute:
BEGIN
DBMS_OUTPUT.PUT_LINE(multipack.g_myvar);
END;
Dick: 0, Hazel: 0
Section 13
BEGIN
CALL drop_proc;
END;
(1) Points
Section 13
41. Examine the following trigger. It should raise an application error if a user tries to update an
employee's
last name. It should allow updates to all other columns of the EMPLOYEES table. What should be
coded at line A?
BEGIN
-- Line A
END IF;
END;
(1) Points
IF UPDATE('LAST_NAME') THEN
IF UPDATING THEN
42. You need to disable all triggers that are associated with DML statements on the DEPARTMENTS
table. Which of the following commands should you use? (1) Points
ALTER TABLE departments DISABLE ALL TRIGGERS; (*)
43. You can code COMMIT and ROLLBACK statements in a trigger body. True or False? (1) Points
True
False (*)
BEGIN
RAISE_APPLICATION_ERROR(-20201,'Invalid delete');
ROLLBACK;
END;
(1) Points
Section 14
45. Procedure B has its local variable emp_number changed to emp_name. The data type of
emp_id is changed from number to integer. It is compiled successfully. In Signature Mode,
Procedure A, which is dependent on remote Procedure B, will compile and execute successfully.
True or False? (1) Points
True (*)
False
46. When a table is dropped, all PL/SQL subprograms that reference the table are automatically
dropped. True or False? (1) Points
True
False (*)
Section 15
47. Identify some benefits of using conditional compilation. (Choose two) (1) Points (Choose all
correct
answers)
Use new features with the latest database release and disable them with older database versions
(*)
48. Native compilation always runs faster; therefore SQL statements in PL/SQL will always run
faster, also. True or False? (1) Points
True
False (*)
49. What does the following statement do?
DBMS_WARNING.ADD_WARNING_SETTING_CAT('PERFORMANCE','ENABLE','SESSION');
(1) Points
Enables the PERFORMANCE warning category, setting other category settings to disabled.
Enables the PERFORMANCE warning category, leaving other category settings unchanged.
Enables the PERFORMANCE warning category, leaving other category settings unchanged, for the
current session.(*)
50. Obfuscation does not allow anyone to see the source code, including the owner. True or False?
(1) Points
True (*)
False
1. Which one of the following explicit cursor declarations is NOT valid? Mark for Review
(1) Points
wf_countries; (*)
population DESC;
Correct
2. When must you declare and use an explicit cursor?
(1) Points
You need to UPDATE more than one row in a table. You want to use a MERGE statement. You
need to SELECT more than one row from a table. (*)
3. You have declared a cursor EMP_CURSOR to select many rows from the EMPLOYEES
B OPEN emp_cursor;
C END LOOP;
D CLOSE emp_cursor;
E LOOP
(1) Points
B, E, A, C, D (*)
E, B, A, C, D
B, E, A, D, C
B, A, E, D, C
Correct
(1) Points
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 2/16
You can not use an INTO clause when declaring an explicit cursor. An explicit cursor can select
from only one table. No joins are allowed. (*)
(1) Points
An implicit cursor, because there is only one 'Grant'. An implicit cursor, because SELECT is a SQL
statement and implicit cursors are
always called "SQL". An explicit cursor, because there could be more than one 'Grant' in the
future. (*)
An explicit cursor, because you can use an implicit cursor only for DML
statements. Correct
DECLARE
v_dept_name departments.department_name%TYPE;
BEGIN
OPEN dept_curs;
LOOP
DBMS_OUTPUT.PUT_LINE(v_dept_name);
END LOOP;
CLOSE dept_curs;
END;
There are 10 rows in the DEPARTMENTS table. What will happen when this code is
executed?
(1) Points
10 rows will be displayed. 10 rows will be displayed, followed by a row of NULL values. The last
row will be displayed twice. (*)
A NO_DATA_FOUND exception will be raised. The loop will execute for ever; the same 10 rows will
be displayed over and over
again. Correct
7. You must make sure you have the same number of variables in your INTO statement
as you have in your SELECT list. True or False? Mark for Review
(1) Points
True (*)
False
Correct
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 3/16
DECLARE
v_dept_name departments.department_name%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_dept_name);
CLOSE dept_curs;
END LOOP;
END;
(1) Points
Nothing is wrong, all the rows will be FETCHed and displayed. The OPEN statement should be
inside the loop. The EXIT WHEN ... statement should be coded outside the loop. The CLOSE
statement should be coded after END LOOP; (*)
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
OPEN emp_curs;
CLOSE emp_curs;
END;
(1) Points
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. (*)
Correct
10. Which of the following best describes the difference between implicit and explicit
Implicit cursors are used for SELECT statements, while explicit cursors are used
for DML statements. Implicit cursor are named by the PL/SQL programmer, while explicit cursors
are
always named SQL. Implicit cursors are defined automatically by Oracle, while explicit cursors
must
Implicit cursors store rows on disk, while explicit cursors store rows in memory.
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 4/16
Correct
11. Which statement correctly places the employee id and last name into the stated
variables?
DECLARE
v_empno employees.employee_id%TYPE;
v_lname employees.last_name%TYPE;
BEGIN
...
(1) Points
Correct
(1) Points
Because an implicit cursor is always called SQL. Because an implicit cursor is OPENed and CLOSEd
automatically by Oracle. (*)
Correct
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
OPEN emp_curs;
LOOP -- Point A
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) Points
Smith (*)
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 5/16
Jones
An INVALID_CURSOR exception will be raised when you try to FETCH the row. Correct
14. There are 8 countries in REGION_ID 13 (Central America). What will happen when the
DECLARE
v_country_name wf_countries.country_name%TYPE;
BEGIN
OPEN country_curs;
WHILE country_curs%FOUND
LOOP
DBMS_OUTPUT.PUT_LINE(v_country_name);
ECND LOOP; LOSE country_curs;
END;
(1) Points
Eight rows will be fetched and displayed successfully. The last seven rows will be fetched and
displayed. The block will execute, but no rows will be displayed. (*)
The block will fail because you can not use a WHILE loop with an explicit cursor. None of the
above. Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer. Section 1
1. How must you reference one field which is part of a PL/SQL record?
(1) Points
field_name.record_name
record_name.field_name (*)
record_name(field_name)
field_name OF record_name
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 6/16
2. You can reference explicit cursor attributes directly in a SQL statement. True or False?
(1) Points
True
False (*)
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
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?
(1) Points
v_country(country_name));
(*)
Correct
CURSOR country_curs IS
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. How would you exit from the FETCH loop?
(1) Points
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 7/16
Correct
5. Which of the following explicit cursor attributes evaluates to TRUE if the most recent
(1) Points
%ISOPEN
%NOTFOUND
%FOUND (*)
%ROWCOUNT
Correct
DECLARE
CURSOR dept_loc_cursor IS
v_dept_loc dept_loc_cursor%ROWTYPE;
(1) Points
Three (*)
None
Correct
DECLARE
CURSOR emp_cursor IS
FROM employees;
v_empcurs emp_cursor%ROWTYPE;
(1) Points
Scalar
Record (*)
Cursor
Row
Correct
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 8/16
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer. Section 1
DECLARE
BEGIN
END LOOP;
END;
To display the salary of an employee, what code should you write at Point A?
(1) Points
emp_record.salary (*)
emp_cursor.salary
employees.salary
emp_record.employees.salary
TO_CHAR(salary)
Correct
(1) Points
The exception handling is done automatically. . The OPEN, CLOSE, FETCH and EXIT from the loop
are done automatically. (*)
You can OPEN the same cursor twice at the same time. Because there is less code, the loop
executes faster. %ROWCOUNT increments automatically each time a row is FETCHed. Correct
BEGIN
DBMS_OUTPUT.PUT_LINE(emp_record.last_name);
END LOOP;
(1) Points
EMP_RECORD has not been explicitly declared. The cursor has not been OPENed. You cannot
reference EMP_RECORD outside the loop. (*)
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 9/16
Correct
4. Which one of the following is a valid cursor FOR loop with a subquery?
(1) Points
FOR emp_rec IN (SELECT last_name || first_name FROM employees) LOOP ... FOR emp_rec IN
(SELECT UPPER(last_name) FROM employees) LOOP ... FOR emp_rec IN SELECT last_name,
salary*12 "ANNSAL" FROM employees LOOP
... FOR emp_rec IN (SELECT last_name, salary*12 "ANNSAL" FROM employees) LOOP
... (*)
(1) Points
The execution speed is slower. You cannot declare the cursor in the declaration section. You
cannot use the cursor to join two or more tables. There are no disadvantages. Correct
6. A cursor FOR loop using a subquery can extensively shorten code length when
(1) Points
True (*)
False
Correct
(1) Points
FOR loc_rec IN 1 .. loc_curs%ROWCOUNT LOOP ... WHILE loc_rec IN loc_curs LOOP ... FOR loc_curs
IN loc_rec LOOP ...
IF loc_rec IN loc_curs LOOP ... FOR loc_rec IN loc_curs LOOP ... (*)
Correct
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 10/16
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer. Section 1
(1) Points
You cannot reference a cursor parameter in a WHERE clause. The parameter should be coded as:
(p_loc_id NUMBER) (*)
CURSOR emp_curs
(1) Points
OPEN emp_curs(20);
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?
(1) Points
19 cursors, all in the same PL/SQL block. 19 cursors in 19 PL/SQL blocks (one in each block). 20
cursors, in case an extra row is inserted into WF_WORLD_REGIONS later. One cursor with a
parameter in the WHERE clause. (*)
4. Using parameters with a cursor, you can open and close the cursor several times in a
block, returning a different active set each time. True or False? Mark for Review
(1) Points
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 11/16
True (*)
False
Correct
DECLARE
v_emp_rec emp_curs%ROWTYPE;
BEGIN
.... You want to open the cursor, passing value 50 to the parameter. Which of the following
(1) Points
50
v_deptid
100 / 2
Correct
Test: Quiz: Using Cursors for Update Review your answers, feedback, and question scores below.
An asterisk (*) indicates a correct answer. Section 1
1. If the rows you attempt to reserve using FOR UPDATE have already been locked by
another session and you use the NOWAIT option, what is the outcome? Mark for Review
(1) Points
The block executes successfully with no errors. The server will wait until the locks have been
released by the other user. An Oracle server error occurs. (*)
Your rows will override the other users' lock and your block will execute
successfully. Correct
CURSOR emp_dept_curs IS
(1) Points
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 12/16
-- Point A -- ;
You want to lock fetched rows from EMPLOYEES, but NOT lock fetched rows from
FOR UPDATE
FOR UPDATE of salary (*)
Correct
3. 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? Mark for Review
(1) Points
When an UPDATE ... WHERE CURRENT OF cursor_name; is executed. When you CLOSE the cursor.
When your block finishes executing. When you explicitly COMMIT or ROLLBACK your transaction.
(*)
--Block A
DECLARE
CURSOR emp_cursor IS
FROM employees
WHERE department_id = 80
--Block B
DECLARE
CURSOR emp_cursor IS
FROM employees
WHERE department_id = 80
NOWAIT;
(1) Points
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. Correct
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 13/16
CURSOR country_curs IS
FROM wf_countries
Another user updates a row in WF_COUNTRIES but does not COMMIT the update. What
(1) Points
Your block fails because you should have coded: FOR UPDATE WAIT (10);
Correct
6. 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
FROM employees
-- Line A -- ;
(1) Points
FOR LOCK
Correct
(1) Points
Only with an UPDATE, not with a DELETE. Only with a DELETE, not with an UPDATE. When the
cursor is declared as SELECT ... FOR UPDATE ...; (*)
When the cursor is based on a single table (not on a join). When the cursor has not been OPENed.
Correct
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 14/16
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer. Section 1
1. Which of the following is NOT allowed when using multiple cursors with parameters? Mark for
Review
(1) Points
You cannot use cursor FOR loops. You cannot declare the cursors FOR UPDATE. You cannot declare
a cursor based on a join. You cannot OPEN more than one cursor at the same time. None of the
above, they are all allowed. (*)
Correct
2. Assume your schema contains 25 tables. How many explicit cursors can you declare and use
within a single PL/SQL block? Mark for Review
(1) Points
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). Correct
CURSOR region_cur IS
v_region_rec region_cur%ROWTYPE;
v_country_rec country_cur%ROWTYPE;
BEGIN
OPEN region_cur;
LOOP
(1) Points
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 15/16
OPEN country_cur;
Correct
4. Assume that table BIGDEPTS contains 100 rows, and table BIGEMPS contains 1000
CURSOR bigdept_cur IS
CURSOR bigemp_cur IS
BEGIN
DBMS_OUTPUT.PUT_LINE (dept_rec.department_name);
IF emp_rec.department_id=dept_rec.department_id
END IF;
END LOOP;
END LOOP;
END;
(1) Points
It is doing a Cartesian Product, joining every employee with every department and
displaying 1100 lines of output. It reads 1000 employee rows every time BIGEMP_CUR is OPENed,
and then
It is using cursor FOR loops, which are less efficient than OPENing and CLOSEing
5. Which of the following is a good reason to use two cursors in a single PL/SQL block?
(1) Points
To allow one cursor to be opened twice at the same time. When two tables are related to each
other (often by a foreign key) and we want to
To allow rows to be locked as they are FETCHed. To speed up the execution of the PL/SQL block.
8/15/2019 -Section-5
http://slidepdf.com/reader/full/-section-5 16/16
6. 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
CURSOR dept_curs IS
ORDER BY department_id;
(1) Points
CURSOR emp_curs IS
(*)
CURSOR emp_curs IS
ORDER BY department_id;
CURSOR emp_curs
(p_dept_id departments.department_id%TYPE) IS
(*)
CURSOR emp_curs IS
Revise las respuestas, los resultados y las puntuaciones de las preguntas que se muestran a
continuación. Las respuestas correctas están marcadas con un asterisco (*). Section 6 (Responder
todas las preguntas de esta sección)
1. Which of the following statements about user-defined PL/SQL records is NOT true? (1/1)
Puntos It can be a component of another PL/SQL record.It can be used as an OUT parameter in a
package procedure.It can be defined as NOT NULL.It is not the same as a row in a database table.It
must contain one or more components, but all the components must have scalar datatypes.
(*)Correct
2. You can store a whole record in a single variable using %ROWTYPE or by creating your own
record structure as a type and then declaring a variable of that type. (1/1) Puntos True
(*)FalseCorrect
2. You can use %ROWTYPE with tables and views. (1/1) Puntos True (*)
FalseCorrect
4. Which of the following will successfully create a record type containing two fields, and a record
variable of that type? (1/1) Puntos TYPE person_type IS (l_name VARCHAR2(20),gender CHAR(1));
person_rec TYPE person_type;
6 Lesson 1.Prueba: PL/SQL Section 6 Quiz Revise las respuestas, los resultados y las puntuaciones
de las preguntas que se muestran a continuación. Las respuestas correctas están marcadas con un
asterisco (*).
2.7. Which of the following methods can be used to reference elements of an INDEX BY table?
(Choose three.) (1/1) Puntos COUNT (*)PREVIOUSFIRST (*)DROPEXISTS (*)Correct
8. Which of these PL/SQL data structures can NOT store a collection? (1/1) Puntos A PL/SQL record
(*)An INDEX BY table of records
Correct
9. Which of these PL/SQL data structures could store a complete copy of the employees table, i.e.,
20 complete table rows? (1/1) Puntos
A record
An INDEX BY table
(1/1) Puntos
True
False (*)CorrectPrue
The following code declares a PL/ SQL record with the same structure as a row of the departments
table.
DECLARE
V_dept_rec departments%ROWTYPE;
True (*)
True(*)
Which of the following successfully declares an INDEX BY table of records which could be used to
store copies of complete rows from the departments table?
DECLARE
INDEX BY BINARY_INTEGER;
DECLARE
INDEXED BY NUMBER;
DECLARE
INDEX BY BINARY_INTEGER;
(*)
DECLARE
INDEX BY BINARY_INTEGER;
What is the largest number of elements (i.e., records) that an INDEX BY table of records can
contain?
32767
100
4096
None of these.
False
%ROWTYPE
a user-defined record
True (*)
False
INDEX BY VIEW
To declare an INDEX BY table, we must first declare a type and then declare a collection variable of
that type. True or False?
True (*)
False
Which of the following methods can be used to reference elements of an INDEX BY table? (Choose
three.)
PREVIOUS
EXISTS (*)
FIRST (*)
DROP
COUNT (*)
An INDEX BY TABLE primary key cannot be negative.
True
False (*)
DECLARE
(department_id departments.department_id%TYPE,
department_name departments.department_name%TYPE);
(first_name employees.first_name%TYPE,
last_name employees.last_name%TYPE),
dept_info dept_info_type);
v_dept_info_rec dept_info_type;
v_emp_dept_rec emp_dept_type;
one
four
two (*)
three
The following code declares a PL/SQL record with the same structure as a row of the departments
table. True or False?
DECLARE
v_dept_rec departments%ROWTYPE;
...
True (*)
False
Which of the following statements about user-defined PL/SQL records is NOT true?
You can store a whole record in a single variable using %ROWTYPE or by creating your own record
structure as a type and then declaring a variable of that type.
True (*)
False
Which of the following will successfully create a record type containing two fields, and a record
variable of that type?
TYPE person_type IS (l_name VARCHAR2(20),
gender CHAR(1));
person_rec person_type;
(l_name VARCHAR2(20),
gender CHAR(1));
gender CHAR(1));
(l_name VARCHAR2(20),
gender CHAR(1));
person_rec person_type;
(*)
Section 7 Quiz
1. What is the correct syntax to associate an exception named EXCEPNAME with the
nonpredefined Oracle Server error ORA-02292? Mark for Review
(1) Points
Correct
2. Which of these exceptions would need to be raised explicitly by the PL/SQL programmer?
(1) Points
OTHERS
Correct
3. Which kinds of exceptions are raised implicitly (i.e., automatically)? (Choose two.)
(1) Points
All errors
User-defined errors
Correct
4. How would you trap Oracle Server exception ORA-01403: no data found?
(1) Points
Correct
5. An ORA-1400 exception is raised if an attempt is made to insert a null value into a NOT
NULL column. DEPARTMENT_ID is the primary key of the DEPARTMENTS table. What will
DECLARE
e_not_null EXCEPTION;
BEGIN
VALUES(null, 'Marketing');
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Cannot be null');
END;
(1) Points
The code will not execute because the syntax of the INSERT statement is wrong.
The code will not execute because PRAGMA EXCEPTION_INIT must be coded in the
The code will not execute because the syntax of PRAGMA EXCEPTION_INIT is
wrong.
Correct
Section 7 Quiz
None of these.
Any other kind of exception that can occur within the block
Correct
7. Which of the following EXCEPTION sections are constructed correctly? (Choose two.)
(1) Points
EXCEPTION
END;
EXCEPTION
END;
(*)
EXCEPTION
END;
(*)
EXCEPTION
END;
Correct
8. Examine the following code. Why does this exception handler not follow good practice
guidelines?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
EXCEPTION
END;
(1) Points
The exception handler should test for the named exception NO_DATA_FOUND. (*)
Correct
(1) Points
Code is more readable because error-handling routines can be written in the same
Correct
(1) Points
True (*)
False
Correct
Section 7 Quiz
<<outer>>
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 10;
DECLARE
BEGIN
outer.v_myvar := 20;
outer.v_myvar := 30;
END;
v_myvar := 40;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(v_myvar);
END;
(1) Points
40
10
20 (*)
200
30
Correct
(1) Points
By PRAGMA EXCEPTION_INIT
Correct
13. 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 (*)
Correct
14. Department-id 99 does not exist. What will be displayed when the following code is
executed?
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
EXCEPTION
(1) Points
END;
None of these.
Correct
15. A user-defined exception must be declared as a variable of data type EXCEPTION. True
(1) Points
TRUE (*)
FALSE
Instead, you must assign values to local variables. Then use the variables in the SQL statement
True (*)
While a PL/SQL block is executing, more than one exception can occur at the same time. True or
False?
TRUE
FALSE (*)
Which of the following EXCEPTION sections are constructed correctly? (Choose two.)
(Choose all correct answers)
EXCEPTION
END;
EXCEPTION
END;
(*)
EXCEPTION
END;
EXCEPTION
END;
(*)
The following EXCEPTION section is constructed correctly. True or False?
EXCEPTION
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END;
True (*)
False
Which of the following is NOT an advantage of including an exception handler in a PL/SQL block?
Code is more readable because error-handling routines can be written in the same block
in which the error occurred
User-defined errors
Examine the following code fragment. At Line A, you want to raise an exception if the fetched
salary value is greater than 30000. How can you do this?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
END IF;
...
Test for WHEN OTHERS in the exception section, because WHEN OTHERS traps all
exceptions.
Define an EXCEPTION variable and associate it with an Oracle Server error number using
PRAGMA EXCEPTION_INIT.
TOO_MANY_ROWS
DUP_VAL_ON_INDEX
ZERO_DIVIDE
NO_DATA_FOUND
How can you retrieve the error code and error message of any Oracle Server exception?
By using RAISE_APPLICATION_ERROR
Examine the followiing code. Which exception handlers would successfully trap the exception
which will be raised when this code is executed? (Choose two.)
DECLARE
BEGIN
OPEN emp_curs;
CLOSE emp_curs;
EXCEPTION ...
END;
WHEN CURSOR_NOT_OPEN
WHEN INVALID_FETCH
WHEN NO_DATA_FOUND
DECLARE
e_outer_excep EXCEPTION;
BEGIN
DECLARE
e_inner_excep EXCEPTION;
BEGIN
RAISE e_outer_excep;
END;
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Outer raised');
DBMS_OUTPUT.PUT_LINE('Inner raised');
END;
The code will propagate the e_outer_excep back to the calling environment.
The code will execute successfully and 'Outer Raised' will be displayed.
The code will fail to compile because e_inner_excep was declared but never RAISEd.
The code will fail to compile because e_inner_excep cannot be referenced in the outer
block. (*)
There are three employees in department 90. What will be displayed when this code is executed?
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('Message 1');
BEGIN
DBMS_OUTPUT.PUT_LINE('Message 2');
END;
DBMS_OUTPUT.PUT_LINE('Message 3');
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Message 4');
END;
Message 1
None of these.
Message 1
Message 3
Message 4
Message 1
Message 4
(*)
DECLARE
e_myexcep EXCEPTION;
BEGIN
DBMS_OUTPUT.PUT_LINE('Message 1');
RAISE e_myexcep;
DBMS_OUTPUT.PUT_LINE('Message 2');
EXCEPTION
DBMS_OUTPUT.PUT_LINE('Message 3');
RAISE e_myexcep;
DBMS_OUTPUT.PUT_LINE('Message 4');
END;
The code will execute but will return an unhandled exception to the calling environment.
(*)
The code will not execute because it contains at least one syntax error.
Message 1
Message 3
Message 1
Message 2
Message 3
Message 4
Message 1
Message 3
Message 4
By PRAGMA EXCEPTION_INIT
PRAGMA EXCEPTION_INIT
RAISE(error_number, exception_name);
FLAG exception_name;
The following three steps must be performed to use a user-defined exception: - Raise the
exception - Handle the exception - Declare the exception In what sequence must these steps be
performed?
Which of the following are NOT good practice guidelines for exception handling? (Choose two.)
♦Test your code with different combinations of data to see what potential errors can happen.
♦Include a WHEN OTHERS handler as the first handler in the exception section. (*)
♦Handle specific named exceptions where possible, instead of relying on WHEN OTHERS.
♦Any other kind of exception that can occur within the block
♦A compile-time error occurs because the PL/SQL code references a non-existent table.
♦The programmer forgets to declare a cursor while writing the PL/SQL code.
EXCEPTION
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END;
♦True (*)
♦False
5. Only one exception can be raised automatically during one execution of a PL/SQL block. True or
False?
♦True (*)
♦False
6. Which of the following EXCEPTION sections are constructed correctly? (Choose three.)
♦EXCEPTION
END;
(*)
♦EXCEPTION
END;
(*)
♦EXCEPTION
END;
♦EXCEPTION
END;
(*)
♦EXCEPTION
END;
7. Examine the following code. Why does this exception handler not follow good practice
guidelines? (Choose two.)
DECLARE
v_dept_name departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_dept_name FROM departments
EXCEPTION
END;
♦The exception handler should test for the named exception NO_DATA_FOUND. (*)
♦The exception section should include a WHEN TOO_MANY_ROWS exception handler. (*)
♦Code is more readable because error-handling routines can be written in the same block in which
the error occurred
♦NO_DATA_FOUND
♦TOO_MANY_ROWS
♦ZERO_DIVIDE
♦DUP_VAL_ON_INDEX
DECLARE
v_count NUMBER;
BEGIN
EXCEPTION …
END;
♦NO_DATA_FOUND
♦ZERO_DIVIDE (*)
♦SQL%ROWCOUNT = 0
♦OTHERS (*)
♦OTHER
4. Examine the following code. The UPDATE statement will raise an ORA-02291 exception.
BEGIN
EXCEPTION
END;
♦The code will execute and insert error number 02291 into error_log_table.
♦The code will fail because SQLCODE has not been declared.
♦The code will fail because we access error message numbers by using SQLERRNUM, not
SQLCODE.
♦The code will fail because we cannot use functions like SQLCODE directly in a SQL statement. (*)
5. What is the correct syntax to associate an exception named EXCEPNAME with the non-
predefined Oracle Server error ORA-02292?
♦User-defined errors
7. Examine the following code. At Line A, you want to raise an exception if the employee’s
manager_id is null. What kind of exception is this?
DECLARE
v_mgr_id employees.manager_id%TYPE;
BEGIN
— Line A
END IF;
…
♦A constraint violation
♦A NO_DATA_FOUND exception
8. An ORA-1400 exception is raised if an attempt is made to insert a null value into a NOT NULL
column. DEPARTMENT_ID is the primary key of the DEPARTMENTS table. What will happen when
the following code is executed?
DECLARE
e_not_null EXCEPTION;
BEGIN
VALUES(null, ‘Marketing’);
EXCEPTION
DBMS_OUTPUT.PUT_LINE(‘Cannot be null’);
END;
♦The code will not execute because the syntax of PRAGMA EXCEPTION_INIT is wrong.
♦The code will not execute because PRAGMA EXCEPTION_INIT must be coded in the DECLARE
section. (*)
♦The code will not execute because the syntax of the INSERT statement is wrong.
10. Which of the following best describes a predefined Oracle Server error?
♦Has a standard Oracle error number but must be declared and named by the PL/SQL programmer
♦Has a standard Oracle error number and a standard name which can be referenced in the
EXCEPTION section (*)
♦Is not raised automatically but must be declared and raised explicitly by the PL/SQL programmer
11. How would you trap Oracle Server exception ORA-01403: no data found?
12. A PL/SQL block executes and an Oracle Server exception is raised. Which of the following
contains the text message associated with the exception?
♦SQLCODE
♦SQLERRM (*)
♦SQL%MESSAGE
♦SQL_MESSAGE_TEXT
♦An exception which has a predefined Oracle error number but no predefined name.
♦An exception handler which the user (the programmer) includes in the EXCEPTION section.
♦An exception which is not raised automatically by the Oracle server, but must be declared and
raised explicitly by the PL/SQL programmer. (*)
3. You want to display your own error message to the user. What is the correct syntax to do this?
♦RAISE application_error;
♦None of the above. They are raised automatically by the Oracle server.
5. What will be displayed when the following code is executed?
DECLARE
e_myexcep EXCEPTION;
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Message 1’);
RAISE e_myexcep;
DBMS_OUTPUT.PUT_LINE(‘Message 2’);
EXCEPTION
DBMS_OUTPUT.PUT_LINE(‘Message 3’);
RAISE e_myexcep;
DBMS_OUTPUT.PUT_LINE(‘Message 4’);
END;
♦Message 1
Message 3
♦Message 1
Message 3
Message 4
♦Message 1
Message 2
Message 3
Message 4
♦The code will not execute because it contains at least one syntax error.
♦The code will execute but will return an unhandled exception to the calling environment.(*)
BEGIN
END IF;
EXCEPTION
END;
♦You cannot explicitly raise predefined Oracle Server errors such as NO_DATA_FOUND.
♦BOOLEAN
♦VARCHAR2
♦EXCEPTION (*)
♦NUMBER
♦True
♦False (*)
<<outer>>
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 25;
DECLARE
BEGIN
outer.v_myvar := 30;
v_myvar := v_myvar / 0;
outer.v_myvar := 35;
END;
v_myvar := 40;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(v_myvar);
END;
♦25
♦30 (*)
♦35
♦40
♦100
2. Three blocks (outer, middle and inner) are nested inside each other. A variable is declared in
the middle block. What is the scope of this variable?
DECLARE
v_var1 NUMBER;
BEGIN
DECLARE
v_var2 NUMBER;
BEGIN
v_var1 := ’20’;
END;
v_var2 := 30;
END;
4. Examine the following code. What is the scope and visibility of the outer block’s v_myvar?
DECLARE
v_myvar VARCHAR2(20);
BEGIN
DECLARE
v_myvar VARCHAR2(20);
BEGIN
END:
END;
♦It is in scope and visible in the outer block only.
♦It is visible in both blocks but in scope only in the outer block.
♦It is in scope in both blocks but visible only in the outer block. (*)
♦True (*)
♦False
DECLARE
e_outer_excep EXCEPTION;
BEGIN
DECLARE
e_inner_excep EXCEPTION;
BEGIN
RAISE e_outer_excep;
END;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(‘Outer raised’);
DBMS_OUTPUT.PUT_LINE(‘Inner raised’);
END;
♦The code will execute successfully and ‘Outer Raised’ will be displayed.
♦The code will propagate the e_outer_excep back to the calling environment (Application
Express).
♦The code will fail to compile because e_inner_excep cannot be referenced in the outer block. (*)
♦The code will fail to compile because e_inner_excep was declared but never RAISEd.
7. In a pair of nested blocks, block labels such as <<label_name>> must be used for both blocks or
neither block. True or False?
♦True
♦False (*)
<<outer>>
♦DECLARE
BEGIN
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(v_name);
END;
END;
<<outer>>
♦DECLARE
BEGIN
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(<<outer>>.v_name);
END;
END
<<outer>>
♦DECLARE
BEGIN
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(outer.v_name);
END;
END;(*)
<<outer>>
♦DECLARE
BEGIN
<<inner>>
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(v_name);
END;
END;
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN BEGIN
END;
♦It will fail to compile because you cannot have a subblock inside an exception section.
♦It will fail to compile because e_excep1 is out of scope in the subblock.
♦It will fail to compile because you cannot declare more than one exception in the same block.
♦It will compile successfully and return an unhandled e_excep2 to the calling environment. (*)
10. Explicit cursors are variables and follow the same scoping and visibility rules as other types of
variable. True or False?
♦True (*)
♦False
11. There are three employees in department 90. What will be displayed when this code is
executed?
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Message 1’);
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Message 2’);
END;
DBMS_OUTPUT.PUT_LINE(‘Message 3’);
EXCEPTION
DBMS_OUTPUT.PUT_LINE(‘Message 4’);
END;
♦Message 1
Message 3
Message 4
♦Message 1
Message 4(*)
♦Message 1
12. Non-predefined Oracle Server errors (associated with Oracle error numbers by PRAGMA
EXCEPTION_INIT) can be declared and raised in inner blocks and handled in outer blocks. True or
False?
♦True
♦False (*)
♦An error occurs during execution which disrupts the normal operation of the program. (*)
♦The programmer makes a spelling mistake while writiing the PL/SQL code.
2. Examine the following code. Why does the exception handler not follow good practice
guidelines?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
EXCEPTION
END;
♦The exception handler should test for the named exception NO_DATA_FOUND. (*)
♦Code is more readable because error-handling routines can be written in the same block in which
the error occurred
4. While a PL/SQL block is executing, more than one exception can occur at the same time. True or
False?
♦True
♦False (*)
5. Department-id 99 does not exist. What will be displayed when the following code is executed?
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
END;
♦FLAG exception_name;
♦PRAGMA EXCEPTION_INIT
♦RAISE(error_number, exception_name);
♦B
♦C
♦A and B
♦B and C (*)
♦A and C
8. A user-defined exception must be declared as a variable of data type EXCEPTION. True or False?
♦True (*)
♦False
DECLARE
e_outer_excep EXCEPTION;
BEGIN
DECLARE
e_inner_excep EXCEPTION;
BEGIN
RAISE e_outer_excep;
END;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(‘Outer raised’);
DBMS_OUTPUT.PUT_LINE(‘Inner raised’);
END;
♦The code will fail to compile because e_inner_excep cannot be referenced in the outer block. (*)
♦The code will propagate the e_outer_excep back to the calling environment.
♦The code will execute successfully and ‘Outer Raised’ will be displayed.
♦The code will fail to compile because e_inner_excep was declared but never RAISEd.
10. 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;
BEGIN
END;
EXCEPTION
END;
♦The code will fail because the exception is declared in the inner block but is referenced in the
outer block. (*)
♦The code will fail because line 4 should read: PRAGMA EXCEPTION_INIT(-2292,
e_constraint_violation);
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
END;
♦It will fail to compile because you cannot have a subblock inside an exception section.
♦It will fail to compile because e_excep1 is out of scope in the subblock.
♦It will fail to compile because you cannot declare more than one exception in the same block.
♦It will compile successfully and return an unhandled e_excep2 to the calling environment. (*)
12. Exceptions declared in a block are considered local to that block, and global to all its sub-
blocks. True or False?
♦True (*)
♦False
♦An error which is not automatically raised by the Oracle server (*)
♦Any error which has an Oracle error number of the form ORA-nnnnn
14. Which of the following best describes a predefined Oracle Server error?
♦Has a standard Oracle error number but must be named by the PL/SQL programmer
♦Is not raised automatically but must be declared and raised explicitly by the PL/SQL programmer
♦Has a standard Oracle error number and a standard name which can be referenced in the
EXCEPTION section (*)
15. Which kinds of exceptions are raised implicitly (i.e., automatically)? (Choose two.)
♦User-defined errors
♦All errors
DECLARE
v_emp_rec emp_curs%ROWTYPE;
BEGIN
OPEN emp_curs;
CLOSE emp_curs;
EXCEPTION …
END;
♦WHEN CURSOR_NOT_OPEN
♦WHEN NO_DATA_FOUND
♦WHEN INVALID_FETCH
17. Examine the following code fragment. At Line A, you want to raise an exception if the fetched
salary value is greater than 30000. How can you do this?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
— Line A
END IF;
♦Test for WHEN OTHERS in the exception section, because WHEN OTHERS traps all exceptions.
♦Define an EXCEPTION variable and associate it with an Oracle Server error number using
PRAGMA EXCEPTION_INIT.
18. Which of these exceptions would need to be raised explicitly by the PL/SQL programmer?
♦OTHERS
19. Which of the following statements about actual parameters is NOT true?
♦An actual parameter is declared in the calling environment, not in the called procedure
♦The datatypes of an actual parameter and its formal parameter must be compatible
20. 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?
(You do not need to repeat the detailed code of the procedure, only the header)
IS
BEGIN …
IS
BEGIN … (*)
IS
BEGIN
p_param := p_param * 2;
END;
♦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
BEGIN
double_it(v_result);
END; (*)
♦BEGIN
double_it(20);
END;
22. You want to create a procedure named SOMEPROC which accepts a single parameter named
SOMEPARM. The parameter can be up to 100 characters long. Which of the following is correct
syntax to do this?
(someparm varchar2)
IS
BEGIN …
(*)
(someparm varchar2(100) )
IS
BEGIN…
IS
(someparm VARCHAR2;)
BEGIN…
someparm varchar2(100);
IS
BEGIN…
(someparm 100)
IS
BEGIN …
23. Which of the following can NOT be used as the datatype of a procedure parameter?
24. A PL/SQL stored procedure can accept one or more input parameters and can return one or
more output values to the calling environment. True or False?
♦True (*)
♦False
25. Which of the following are benefits of using PL/SQL subprograms rather than anonymous
blocks? (Choose three.)
♦Easier to write
26. A nested subprogram can only be invoked from the main subprogram. True or False?
♦True (*)
♦False
27. A PL/SQL procedure named MY_PROC1 has been successfully created in the database. The
procedure has no parameters. Which of the following will successfully invoke the procedure in
Application Express? (Choose two.)
♦DECLARE
BEGIN
my_proc1(v_var1);
END;
♦EXECUTE my_proc1;
♦BEGIN
my_proc1;
END;
(*)
BEGIN
my_proc1;
END my_proc2;
(*)
28. A stored PL/SQL procedure can be invoked from which of the following?
A calling application
♦A only
♦A and B
♦A and C
♦B and C
29. The following are the steps involved in creating, and later modifying and re-creating, a PL/SQL
procedure in Application Express. In what sequence should these steps be performed?
Retrieve the saved code from “Saved SQL” in SQL Commands
♦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
♦IN (*)
♦OUT
♦NUMBER
♦VARIABLE
♦CONSTANT
(A IN NUMBER := 20,
B IN NUMBER,
IS …..
32. Suppose you set up a parameter with an explicit OUT mode. What is true about that
parameter?
♦It acts like a constant (its value cannot be changed inside the subprogram).
33. Procedure SOMEPROC has five parameters named A, B, C, D, E in that order. The procedure
was called as follows:
SOMEPROC(10,20,D=>50);
♦Positional (*)
♦Named
♦Defaulted
♦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 and thereby increase efficiency. (*)
♦They can do the same job as built-in system functions such as UPPER and ROUND.
35. When creating a user-defined function, the size of the returned values may be up to the size
of any PL/SQL data type. True or False?
♦True
♦False (*)
36. The function avg_ann_sal returns the average annual salary for a particular department. The
example below is a valid use of of this function. True or False?
FROM employees
♦True (*)
♦False
IS
PRAGMA AUTONOMOUS_TRANSACTION
BEGIN
COMMIT;
END log_usage;
♦The subprogram will fail because the PRAGMA statement must be before IS.
♦The subprogram will fail because it is missing AUTHID CURRENT_USER before IS.
♦The compilation will fail because a semicolon after AUTONOMOUS_TRANSACTION is required. (*)
♦The program will compile successfully.
38. User BOB creates procedure MYPROC using the default Definer’s Rights. BOB then executes:
♦TED’s privileges
♦PUBLIC’s privileges
♦SYSTEM’s privileges
♦ORACLE’s privileges
39. User REYHAN creates the following procedure: CREATE PROCEDURE proc1 AUTHID
CURRENT_USER IS v_count NUMBER; BEGIN SELECT COUNT(*) INTO v_count FROM
tom.employees; END; User BILL wants to execute this procedure. What privileges will BILL need?
♦EXECUTE on REYHAN.PROC1
♦SELECT on TOM.EMPLOYEES
♦None of the above. The procedure will fail to compile because REYHAN does not have SELECT
privilege on TOM.EMPLOYEES.
40. A function named MYFUNC has been created. This function accepts one IN parameter of
datatype VARCHAR2 and returns a NUMBER.
You want to invoke the function within the following anonymous block:
DECLARE
v_var1 NUMBER(6,2);
BEGIN
— Line A
END;
♦myfunc(‘Crocodile’) := v_var1;
♦myfunc(v_var1) := ‘Crocodile’;
♦myfunc(v_var1, ‘Crocodile’);
♦myfunc(‘Crocodile’, v_var1);
RETURN NUMBER
IS
BEGIN
END;
♦23
♦11
♦66
♦17 (*)
♦An error message will be displayed because you cannot nest user-defined functions.
43. You have created a function named NEWFUNC. You now change some of the function code,
and try to recreate the function by executing:
What happens?
♦The command fails because you should execute: CREATE AND REPLACE ….;
(p_param NUMBER(4))
RETURN BOOLEAN
IS BEGIN
END badfunc;
♦The datatype of the IN parameter cannot have a precision or scale. It must be NUMBER, not
NUMBER(4). (*)
♦RETURN (p_param > 10); is wrong because you cannot return an expression.
46. Examine the following code (the code of CHILD2 is not shown):
IS v_salary employees.salary%TYPE;
BEGIN
EXCEPTION
END child1;
IS BEGIN
child1;
child2;
EXCEPTION
END parent;
Employee_id 9999 does not exist. What happens when PARENT is executed?
♦CHILD1 handles the exception successfully and ends. PARENT continues to execute and invokes
CHILD2. (*)
♦CHILD1 ends abruptly, PARENT handles the exception successfully and ends. CHILD2 does not
execute.
♦CHILD1 ends abruptly, then PARENT also ends abruptly with an unhandled exception.
♦PARENT fails to compile because you cannot have the same exception handler in two separate
subprograms.
47. 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)
♦Query USER_PARAMETERS
♦Query USER_FUNCTIONS
48. Which Data Dictionary view can be used to display the detailed code of a procedure in your
schema?
♦USER_PROCEDURES
♦USER_OBJECTS
♦USER_SOURCE (*)
♦USER_SUBPROGRAMS
49. An INDEX BY TABLE type can only have one data field.
♦True (*)
♦False
50. You an use %ROWTYPE with tables and views.
♦True (*)
♦False