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 3 - What is the output of the following code?

DECLARE
   grade char(1) := 'B';
BEGIN
   case 
      when grade = 'A' then dbms_output.put_line('Excellent');
      when grade = 'B' then dbms_output.put_line('Very good');
      when grade = 'C' then dbms_output.put_line('Well done');
      when grade = 'D' then dbms_output.put_line('You passed');
      when grade = 'F' then dbms_output.put_line('Better try again');
      else dbms_output.put_line('No such grade');
   end case;
END;

A - It has syntax error, so there will not be any output.

B - B

C - Very good

D - No such grade

Answer : C

Q 4 - 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 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 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 6 - Which of the following is not among the types of PL/SQL records?

A - Table-based

B - View-based

C - Cursor-based records

D - User-defined records

Answer : B

Q 7 - Observe the syntax given below −

CREATE [OR REPLACE ] TRIGGER trigger_name 
{BEFORE | AFTER | INSTEAD OF } 
{INSERT [OR] | UPDATE [OR] | DELETE} 
[OF col_name] 
ON table_name 
[REFERENCING OLD AS o NEW AS n] 
[FOR EACH ROW] 
WHEN (condition)  
DECLARE
   Declaration-statements
BEGIN 
   Executable-statements
EXCEPTION
   Exception-handling-statements
END;

The INSTEAD OF clause is used for creating trigger on a −

A - View

B - Cursor

C - Table

D - Index

Answer : A

Answer : D

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