PL/SQL MOCK TEST
[Link] Copyright © [Link]
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;
A - It has syntax error, so there will not be any output.
B - 200
C - 200
100
D - 100
Q 2 - Which of the following is not true about PL/SQL loop structures?
A - In the basic loop structure, sequence of statements is enclosed between the LOOP and END
LOOP statements.
B - The WHILE loop repeats a statement or group of statements while a given condition is true.
C - The FOR loop executes a sequence of statements multiple times and abbreviates the code
that manages the loop variable.
D - Nesting of loops is not allowed.
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.
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;
A - There is nothing wrong.
B - The IF statement is not required.
C - There should be an END LOOP statement.
D - The exit statement should be in capital letters.
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;
A-4
B-4
C-4
D - None of the above.
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;
A - 10
B-8
C-7
D-9
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;
A - 11
B - 10
C-9
D - Infinite loop.
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;
A - 11
B - 10
C - 29
D - 30
Q 9 - Consider a variable named greetings declared as −
greetings varchar211 := 'Hello World';
What will be the output of the code snippet
dbms_output.put_line SUBSTR(greetings, 7, 5);
A - World
B - Hello
C - orld
D - None of the above.
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.
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 VARRAY100 OF INTEGERS;
B - VARRAY grades IS VARRAY100 OF INTEGER;
C - TYPE grades VARRAY100 OF INTEGER;
D - TYPE grades IS VARRAY100 OF INTEGER;
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.
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.
B - You can initialize the VARRAY elements using the constructor method of the VARRAY type,
which has the same name as the VARRAY.
C - VARRAYs are one-dimensional arrays.
D - None of the above.
Q 14 - A subprogram can be created −
A - At schema level.
B - Inside a package.
C - Inside a PL/SQL block.
D - All of the above.
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.
C - An IN OUT parameter passes an initial value to a subprogram and returns an updated value to
the caller.
D - All of the above.
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;
A-2
B-5
C-0
D - Won’t print anything
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;
A-5
B - 10
C - 25
D-0
Q 18 - Which of the following is a way of passing parameters to PL/SQL subprograms?
A - Positional notation
B - Named notation
C - Mixed notation
D - All of the above.
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.
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 doesn’t have the RETURN clause in function declaration.
B - The RETURN statement is wrong.
C - Function definition should not use the IS keyword
D - Nothing wrong.
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;
A - 46
B - 47
C - 94
D - 23
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;
A-1
B-5
C - 10
D - 125
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 oneormore returned by a SQL statement.
C - The set of rows the cursor holds is referred to as the active set.
D - None of the above.
Q 24 - Which of the following is true about PL/SQL cursors?
A - Explicit cursors are automatically created by Oracle.
B - Implicit cursors are programmer defined cursors.
C - The most recent implicit cursor is called the SQL cursor, and has the attributes like %FOUND,
%ISOPEN, %NOTFOUND, and %ROWCOUNT.
D - All of the above.
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.
C - sql%found, sql%notfound, sql%rowcount.
D - %found, %notfound, %rowcount.
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
Loading [MathJax]/jax/output/HTML-CSS/[Link]