- PL/SQL - Home
- PL/SQL - Overview
- PL/SQL - Environment
- PL/SQL - Basic Syntax
- PL/SQL - Data Types
- PL/SQL - Variables
- PL/SQL - Constants and Literals
- PL/SQL - Operators
- PL/SQL - Conditions
- PL/SQL - Loops
- PL/SQL - Strings
- PL/SQL - Arrays
- PL/SQL - Procedures
- PL/SQL - Functions
- PL/SQL - Cursors
- PL/SQL - Records
- PL/SQL - Exceptions
- PL/SQL - Triggers
- PL/SQL - Packages
- PL/SQL - Collections
- PL/SQL - Transactions
- PL/SQL - Date & Time
- PL/SQL - DBMS Output
- PL/SQL - Object Oriented
PL/SQL Mock Test
This section presents you various set of Mock Tests related to PL/SQL. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
PL/SQL Mock Test II
Q 1 - What will be the output of the following code snippet?
DECLARE
a number(3) := 100;
b number(3) := 200;
BEGIN
IF( a = 100 ) THEN
IF( b <> 200 ) THEN
dbms_output.put_line(b);
END IF;
END IF;
dbms_output.put_line(a);
END;
Answer : D
Q 2 - Which of the following is not true about PL/SQL loop structures?
B - The WHILE loop repeats a statement or group of statements while a given condition is true.
Answer : D
Q 3 - Which of the following is not true about labelling PL/SQL loops?
A - PL/SQL loops can be labelled.
B - The label should be enclosed by angle brackets (< and >).
C - The label name appears at the beginning of the LOOP statement.
D - The label name can also appear at the end of the LOOP statement or with an EXIT statement.
Answer : B
Explanation
The label should be enclosed by double angle brackets (<< and >>)
Q 4 - What is wrong in the following code snippet?
DECLARE
x number := 1;
BEGIN
LOOP
dbms_output.put_line(x);
x := x + 1;
IF x > 10 THEN
exit;
END IF;
dbms_output.put_line('After Exit x is: ' || x);
END;
B - The IF statement is not required.
Answer : C
Q 5 - What is the output of the following code?
DECLARE
x number := 4;
BEGIN
LOOP
dbms_output.put_line(x);
x := x + 1;
exit WHEN x > 5;
END LOOP;
dbms_output.put_line(x);
END;
Answer : A
Q 6 - Consider the following code snippet: how many times the loop will run?
DECLARE
a number(2) := 9;
BEGIN
WHILE a < 30 LOOP
a := a + 3;
END LOOP;
END;
Answer : C
Q 7 - Consider the following code snippet: how many times the loop will run?
DECLARE
a number(2);
BEGIN
FOR a in 10 .. 20 LOOP
END LOOP;
END;
Answer : A
Q 8 - Consider the following code snippet: what will be the output?
DECLARE a number(2) ; BEGIN FOR a IN REVERSE 10 .. 20 LOOP END LOOP; dbms_output.put_line(a); END;
Answer : B
Q 9 - Consider a variable named greetings declared as −
greetings varchar2(11) := 'Hello World';
What will be the output of the code snippet
dbms_output.put_line ( SUBSTR (greetings, 7, 5));
Answer : A
Q 10 - Which of the following is not true about the PL/SQL data structure VARRAY?
A - It is a fixed-size sequential collection of elements.
B - The elements can of various data types.
C - It is used to store an ordered collection of data.
D - Each element in a VARRAY has an index associated with it.
Answer : B
Q 11 - Which of the following is the correct syntax for creating a VARRAY named grades, which can hold 100 integers, in a PL/SQL block?
A - TYPE grades IS VARRAY(100) OF INTEGERS;
B - VARRAY grades IS VARRAY(100) OF INTEGER;
Answer : D
Q 12 - Which of the following is true about the PL/SQL data structure VARRAY?
A - It also has a maximum size that cannot be changed.
B - A VARRAY type is created with the CREATE VARRAY statement, at the schema level.
C - Maximum size of a VARRAY can be changed using the ALTER TYPE statement.
D - Maximum size of a VARRAY can be changed using the ALTER VARRAY statement.
Answer : C
Q 13 - Which of the following is not true about the PL/SQL data structure VARRAY?
A - In oracle environment, the starting index for VARRAYs is always 1.
Answer : D
Q 14 - A subprogram can be created −
Answer : D
Q 15 - Which of the following is true about the parameter modes in PL/SQL Subprograms?
A - An IN parameter lets you pass a value to the subprogram. It is a read-only parameter.
B - An OUT parameter returns a value to the calling program.
Answer : D
Q 16 - What will be printed by the following PL/SQL block?
DECLARE
a number;
b number;
c number;
PROCEDURE findMin(x IN number, y IN number, z OUT number) IS
BEGIN
IF x < y THEN
z:= x;
ELSE
z:= y;
END IF;
END;
BEGIN
a:= 2;
b:= 5;
findMin(a, b, c);
dbms_output.put_line(c);
END;
Answer : A
Q 17 - What will be printed by the following PL/SQL block?
DECLARE a number; PROCEDURE squareNum(x IN OUT number) IS BEGIN x := x * x; END; BEGIN a:= 5; squareNum(a); dbms_output.put_line(a); END;
Answer : C
Q 18 - Which of the following is a way of passing parameters to PL/SQL subprograms?
Answer : D
Q 19 - Which of the following is not true about the PL/SQL functions?
A - A PL/SQL function is same as a procedure except that it returns a value.
B - The function body must contain a RETURN statement.
C - The RETURN clause does not specify the data type of the return value.
D - The AS keyword is used instead of the IS keyword for creating a standalone function.
Answer : C
Q 20 - What is wrong in the following code snippet?
CREATE OR REPLACE FUNCTION totalCustomers total number(2) := 0; BEGIN SELECT count(*) into total FROM customers; RETURN total; END;
A - It doesnt have the RETURN clause in function declaration.
B - The RETURN statement is wrong.
Answer : A
Explanation
The correct code should be
CREATE OR REPLACE FUNCTION totalCustomers RETURN number IS total number(2) := 0; BEGIN SELECT count(*) into total FROM customers; RETURN total; END;
Q 21 - What would be the output of the following code?
DECLARE
a number;
b number;
c number;
FUNCTION fx(x IN number, y IN number)
RETURN number
IS
z number;
BEGIN
IF x > 2*y THEN
z:= x;
ELSE
z:= 2*y;
END IF;
RETURN z;
END;
BEGIN
a:= 23;
b:= 47;
c := fx(a, b);
dbms_output.put_line(c);
END;
Answer : C
Q 22 - What would be the output of the following code?
DECLARE
num number;
fn number;
FUNCTION fx(x number)
RETURN number
IS
f number;
BEGIN
IF x=0 THEN
f := 1;
ELSE
f := x * fx(x-1);
END IF;
RETURN f;
END;
BEGIN
num:= 5;
fn := fx(num);
dbms_output.put_line(fn);
END;
Answer : D
Q 23 - Which of the following is not true about PL/SQL cursors?
A - A cursor is a view on a table.
B - A cursor holds the rows (one or more) returned by a SQL statement.
C - The set of rows the cursor holds is referred to as the active set.
Answer : A
Explanation
A cursor is a memory area, known as context area, for processing an SQL statement, which contains all information needed for processing the statement.
Q 24 - Which of the following is true about PL/SQL cursors?
A - Explicit cursors are automatically created by Oracle.
Answer : C
Q 25 - Observe the following code and fill in the blanks −
DECLARE
total_rows number(2);
BEGIN
UPDATE employees
SET salary = salary + 500;
IF ____________ THEN
dbms_output.put_line('no employees selected');
ELSIF ___________ THEN
total_rows := _____________;
dbms_output.put_line( total_rows || ' employees selected ');
END IF;
END;
A - %notfound, %found, %rowcount.
B - sql%notfound, sql%found, sql%rowcount.
Answer : B
Answer Sheet
| Question Number | Answer Key |
|---|---|
| 1 | D |
| 2 | D |
| 3 | B |
| 4 | C |
| 5 | A |
| 6 | C |
| 7 | A |
| 8 | B |
| 9 | A |
| 10 | B |
| 11 | D |
| 12 | C |
| 13 | D |
| 14 | D |
| 15 | D |
| 16 | A |
| 17 | C |
| 18 | D |
| 19 | C |
| 20 | A |
| 21 | C |
| 22 | D |
| 23 | A |
| 24 | C |
| 25 | B |