PL/SQL Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to PL/SQL. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Answer : B

Q 2 - What would be printed when the following code is executed?

DECLARE
      x   NUMBER;
    BEGIN
      
       x := 5;
       x := 10;
       dbms_output.put_line(-x);
       dbms_output.put_line(+x);
       x := -10;
       dbms_output.put_line(-x);
       dbms_output.put_line(+x);
   END;

A - -10

     10

     10

     -10

B - 10

     -10

     10

     -10

C - -10

     +10

     +10

     -10

D - 10

     -10

     -10

     10

Answer : A

Q 3 - 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 5 - 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.

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 9 - Which of the following code is the correct syntax for creating an index-by table named salary that will store integer values along with names and the name field will be the key?

A - TYPE salary IS TABLE OF NUMBER INDEX BY VARCHAR2(20);

B - CREATE TABLE salary OF NUMBER INDEX BY VARCHAR2(20);

C - TYPE salary IS INDEXED TABLE OF NUMBER INDEX BY VARCHAR2(20);

D - None of the above.

Answer : A

plsql_questions_answers.htm
Advertisements