Semester 1 Midterm Exam
Semester 1 Midterm Exam
Semester 1 Midterm Exam
Processing
Procedural (*)
Primary
Proprietary
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. (*)
3. A program which specifies a list of operations to be performed sequentially to achieve the desired result can be called:
declarative
nondeclarative
procedural (*)
low level
4. Using Oracle Application Express, you can create Web applications that include PL/SQL. True or False?
True (*)
False
5. 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
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.
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 component of Oracle Application Express is used to enter and run SQL statements and PL/SQL blocks?
Application Builder
Utilities
Object Browser
11. Which keywords must be included in every PL/SQL block? (Choose two.)
DECLARE
END; (*)
EXCEPTION
BEGIN (*)
DBMS_OUTPUT.PUT_LINE
12. In which part of the PL/SQL block are declarations of variables defined?
Executable
Exception
Declarative (*)
Definition
13. Errors are handled in the Exception part of the PL/SQL block. True or False?
True (*)
False
DECLARE
Correct.
15. Variables can be used in the following ways in a PL/SQL block. (Choose two.)
To comment code.
16. When a variable is defined using the NOT NULL keywords, the variable must contain a value. True or False?
True (*)
False
17. Identify which of the following assignment statements are valid. (Choose three.)
v_last_name := Chandra;
DECLARE
Correct.
19. Which of the following are disadvantages of implicit data type conversions? (Choose two.)
If Oracle changes the conversion rules in the future, your code may not work any more (*)
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= ‘300’;
5 END;
’300′
300 (*)
NULL
21. 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)
22. The DECODE function is available in PL/SQL procedural statements. True or False?
True
False (*)
23. When you use a function to convert data types in a PL/SQL program, it is called ______ conversion.
Explicit (*)
Implicit
TO_CHAR
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;
Character functions
Operators
26. 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
27. 1. Null
2. False
3. True
4. 0
2 and 3
2, 3 and 4
1, 2 and 3 (*)
1, 2, 3 and 4
28. 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 ?
It is shorter than coding NUMBER(8,2)
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
29. If you are using the %TYPE attribute, you can avoid hard coding the:
Table name
Column name
Constraint
30. What is the data type of the variable V_DEPT_TABLE in the following declaration?
DECLARE
Scalar
Composite (*)
LOB
Scalar
Composite
Reference
LOB (*)
True (*)
False
33. Delimiters are _____ that have special meaning to the Oracle database.
identifiers
variables
symbols (*)
34. Which statements about lexical units are true? (Choose two.)
They are optional but can make a PL/SQL block execute faster
They are sequences of characters including letters, digits, tabs, returns and symbols (*)
True
False (*)
36. When an exception occurs within a PL/SQL block, the remaining statements in the executable section of the block are
skipped. True or False?
True (*)
False
37. 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. (*)
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
39. An exception occurs within the inner block of two nested blocks. The inner block does not have an EXCEPTION section.
What always happens?
Both blocks fail and an error message is displayed by the calling environment
DECLARE
BEGIN
DECLARE
varB NUMBER := 8;
BEGIN
END;
DBMS_OUTPUT.PUT_LINE(varB);
END;
12
20
VarB
FROM employees
WHERE employee_id=100;
What is the value of SQL%ISOPEN immediately after the SELECT statement is executed?
True
False (*)
Null
42. 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.
43. Which is the correct way to erase one row from a table?
REMOVE employee_id=100
FROM employees;
WHERE employee_id=100;
TRUNCATE employees
WHERE employee_id=100;
WHERE employee_id=100;
(*)
44. Which one of these SQL statements can be directly included in a PL/SQL executable block?
DELETE FROM employees
WHERE department_id=60;
(*)
WHERE department_id=60;
45. Which rows will be deleted from the EMPLOYEES table when the following code is executed?
DECLARE
BEGIN
END;
No rows. (*)
46. Which one of these SQL statements can be directly included in a PL/SQL executable block?
WHERE employee_id=100;
SET last_name=’Smith’;
(*)
DECLARE
v_holdit employees.last_name%TYPE;
BEGIN …
SELECT *
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100;
(*)
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary
INTO v_salary
FROM employees
WHERE employee_id=100;
(*)
SELECT v_salary
INTO salary
FROM employees
WHERE employee_id=100;
SELECT salary
FROM employees
FROM employees
WHERE employee_id=100
INTO v_salary;
Only one
BEGIN
VALUES (‘NV’,’Neverland’);
COMMIT;
COMMIT;
ROLLBACK;
END;
You have the rows added twice; there are four new rows.
1. In a WHILE loop, the statements inside the loop must execute at least once. True or False?
True
False (*)
2. 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;
BEGIN
DBMS_OUTPUT.PUT_LINE (i);
i := i + 1;
END LOOP;
END;
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 FOR loop, an implicitly declared counter automatically increases or decreases with each iteration. True or False?
True (*)
False
When repeating a sequence of statements until the controlling condition is no longer true (*)
When the controlling condition must be evaluated at the start of each iteration
DECLARE
v_counter PLS_INTEGER := 1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(v_counter);
v_counter := v_counter + 1;
END LOOP;
END;
4 (*)
FOR loop
Basic loop
WHILE loop
9. What kind of statement is best suited for displaying the multiplication table for “sixes”: 6×1=6, 6×2=12 … 6×12=72?
CASE expression
IF statement
CASE statement
v_counter := 1;
LOOP
v_counter := v_counter + 1;
END LOOP;
5 (*)
v_count := 1;
LOOP
v_count := v_count + 1;
END LOOP;
FOR loop
IF-THEN loop
WHILE loop
CASE loop
DECLARE
v_grade CHAR(1);
BEGIN
CASE v_grade
IF ‘A’ THEN
14. 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
15. 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
16. 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;
END;
30 (*)
20
40
10
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;
The inner loop is exited but the outer loop continues execution. (*)
The outer loop is exited but the inner loop continues execution.
18. You want to display multiplication tables for numbers up to 12. The display should look like this:
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. Invoke the function 144 times.
Write an anonymous block which contains 144 calls to DBMS_OUTPUT, each looking like: DBMS_OUTPUT.PUT_LINE(‘7 x 9
= 63’);
BASIC loops
WHILE loops
FOR loops
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?
35
30 (*)
40
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := FALSE;
c BOOLEAN := TRUE;
d BOOLEAN := FALSE;
BEGIN
END IF;
NULL
won’
lost’ (*)
False
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;
UNEQUAL
EQUAL
OTHER (*)
23. 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)
IF … THEN … ELSE
24. How many ELSIF statements are you allowed to have in a compound IF statement?
Only one
They must match the same number as the number of ELSE statements.
IF condition;
THEN statement;
END IF;
IF condition
THEN statement
ENDIF;
You can use a single cursor to fetch a different set of rows each time the cursor is opened. (*)
p_param := ‘ABC’;
OPEN c_curs(p_param);
28. When using a cursor FOR loop, OPEN, CLOSE and FETCH statements should not be explicitly coded. True or False?
True (*)
False
29. Examine the following code. To display the salary of an employee, what must be coded at Point A?
DECLARE
BEGIN
END LOOP;
END;
salary
emp_curs.salary
emp_rec.salary (*)
employees.salary
emp_rec.salary IN emp_curs
END LOOP;
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;
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?
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 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.
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
35. Assume that you have declared a cursor called C_EMP. Which of the following statements about C_EMP is correct? (Choose
two.)
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 emp_curs%ROWTYPE; (*)
emp_rec cursor%ROWTYPE;
37. Which of the following cursor attributes evaluates to TRUE if the cursor is open?
%ISOPEN (*)
%NOTFOUND
%FOUND
%ROWCOUNT
38. 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?
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.
39. Which of the following cursor attributes is set to the total number of rows returned so far?
%ISOPEN
%NOTFOUND
%FOUND
%ROWCOUNT (*)
40. When using multiple nested cursors, what kinds of loops can you use?
41. 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 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.
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(dept_rec.department_name);
DBMS_OUTPUT.PUT_LINE(emp_rec.last_name);
END LOOP;
END LOOP;
END;
You cannot use two different kinds of loop in a single PL/SQL block.
EMP_CURS should not be DECLAREd explicitly; it should be coded as a subquery in a cursor FOR loop.
Nothing is wrong. The block will execute successfully and display all departments and the employees in those departments.
(*)
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?
OPEN emp_curs;
(*)
OPEN emp_curs;
OPEN emp_curs;
OPEN emp_curs;
FETCH emp_curs;
44. An explicit cursor must always be declared, opened and closed by the PL/SQL programmer. True or False?
True
False (*)
1. OPEN my_curs;
2. CLOSE my_curs;
C,D,A,B
C,A,D,B (*)
A,C,D,B
C,A,B,D
46. 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. (*)
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. (*)
48. For which type of SQL statement must you use an explicit cursor?
50. Which of these constructs can be used to fetch multiple rows from a cursor’s active set?
A CASE statement
An IF …. ELSE statement
A basic loop which includes FETCH and EXIT WHEN statements (*)
variables
conditional statements
constants
Procedural (*)
Primary
Proprietary
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
5. 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
PL/SQL code can be developed on one platform and deployed on another (*)
7. Which lines of code will correctly display the message “The cat sat on the mat”? (Choose two.)
8. Every PL/SQL anonymous block must start with the keyword DECLARE. True or False?
True
False (*)
9. Which of the following tools can NOT be used to develop and test PL/SQL code?
Oracle Jdeveloper
Oracle iSQL*Plus
10. Which component of Oracle Application Express is used to enter and run SQL statements and PL/SQL blocks?
Application Builder
Utilities
Object Browser
DECLARE (*)
BEGIN
EXCEPTION (*)
END;
12. Which keywords must be included in every PL/SQL block? (Choose two.)
DECLARE
END; (*)
EXCEPTION
BEGIN (*)
DBMS_OUTPUT.PUT_LINE
13. PL/SQL can convert a VARCHAR2 value containing alphabetic characters to a NUMBER value. True or False?
True
False (*)
Character functions
Operators
1 DECLARE
2 x NUMBER;
3 BEGIN
4 x:= ‘300’;
5 END;
’300′
300 (*)
NULL
16. Which of the following are disadvantages of implicit data type conversions? (Choose two.)
If Oracle changes the conversion rules in the future, your code may not work any more (*)
Explicit (*)
Implicit
TO_CHAR
18. Single row character functions are valid SQL functions in PL/SQL. True or False?
True (*)
False
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;
20. 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
21. If you are using the %TYPE attribute, you can avoid hard coding the:
Table name
Column name
Constraint
v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):=’Harvard’;
23. Which of the following should NOT be used as the name of a variable?
A table name.
Number
Letter (*)
Special character
yesterday’s date
number_of_students_in_the_class
v$testresult (*)
#students
True
False (*)
DECLARE
Correct.
28. Variables can be assigned a value in both the Executable and Declaration sections of a PL/SQL program. True or False?
True (*)
False
29. Identify which of the following assignment statements are valid. (Choose three.)
v_last_name := Chandra;
DECLARE
True (*)
False
32. 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
33. What is the data type of the variable V_DEPT_TABLE in the following declaration?
DECLARE
Scalar
Composite (*)
LOB
34. 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;
outer_var := outer_var || ‘ Zeynep’;
EXCEPTION
DBMS_OUTPUT.PUT_LINE(outer_var);
END;
My
My name (*)
My name is
My name is Zeynep
Inward
Upward
Outward
Downward (*)
36. 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
6
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
38. When an exception occurs within a PL/SQL block, the remaining statements in the executable section of the block are
skipped. True or False?
True (*)
False
39. Which of the following will help to make code easier to read?
Naming variables.
Using %Type.
40. Which of the following is an example of using a case convention for good programming practice?
True (*)
False
42. Which rows will be deleted from the EMPLOYEES table when the following code is executed?
DECLARE
BEGIN
END;
No rows. (*)
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?
DELETE FROM employees
WHERE department_id=60;
(*)
WHERE department_id=60;
DECLARE
v_holdit employees.last_name%TYPE;
BEGIN …
SELECT *
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100;
(*)
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
46. The following anonymous block of code is run:
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.
You have the two new rows added. (*)
A DELETE statement
An UPDATE statement
49. You declare an implicit cursor in the DECLARE section of a PL/SQL block. True or False?
True
False (*)
50. Assume there are 5 employees in Department 10. What happens when the following statement is executed?
UPDATE employees
SET salary=salary*1.1;