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.

Questions and Answers

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

Answer : D

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;

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.

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;

A - 4

     5

     6

B - 4

     5

C - 4

D - None of the above.

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;

A - 10

B - 8

C - 7

D - 9

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;

A - 11

B - 10

C - 9

D - Infinite loop.

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;

A - 11

B - 10

C - 29

D - 30

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));

A - World

B - Hello

C - orld

D - None of the above.

Answer : A

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;

C - TYPE grades VARRAY(100) OF INTEGER;

D - TYPE grades IS VARRAY(100) OF INTEGER;

Answer : D

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;

A - 2

B - 5

C - 0

D - Won’t print anything

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;

A - 5

B - 10

C - 25

D - 0

Answer : C

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.

Answer : D

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.

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;

A - 46

B - 47

C - 94

D - 23

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;

A - 1

B - 5

C - 10

D - 125

Answer : D

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 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 : 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
plsql_questions_answers.htm
Advertisements