MCQs on PL/SQL Basics | Procedural Language in SQL

1. Introduction to PL/SQL Programming

  1. Which of the following is the main feature of PL/SQL?
    a) Object-oriented programming
    b) Procedural programming
    c) Data manipulation language
    d) Query language
  2. Which statement is used to begin a PL/SQL block?
    a) BEGIN
    b) START
    c) BEGIN BLOCK
    d) OPEN
  3. What is the full form of PL/SQL?
    a) Procedural Logic/SQL
    b) Procedural Language/SQL
    c) Program Logic/SQL
    d) Program Language/SQL
  4. PL/SQL is used to perform operations on which type of databases?
    a) MySQL
    b) Oracle
    c) PostgreSQL
    d) SQL Server
  5. Which keyword is used to end a PL/SQL block?
    a) FINISH
    b) END;
    c) STOP;
    d) CLOSE;

2. Structure of PL/SQL Blocks

  1. A PL/SQL block contains which three sections?
    a) Declarations, Begin, and End
    b) Declaration, Execution, and Exception
    c) Variables, Execution, and Loop
    d) Header, Execution, and End
  2. Which of the following is the correct order of a PL/SQL block?
    a) Declarations, Begin, Exception, End
    b) Begin, Declarations, Exception, End
    c) Declarations, Begin, End
    d) Declarations, Begin, Loop, End
  3. Which of the following PL/SQL block structures is mandatory?
    a) Exception block
    b) Declare block
    c) Execution block
    d) All are mandatory
  4. Which section of a PL/SQL block can be used to declare variables and constants?
    a) Declarations
    b) Execution
    c) Exception
    d) Begin
  5. What is the purpose of the EXCEPTION section in a PL/SQL block?
    a) To handle database connections
    b) To declare variables
    c) To handle errors
    d) To execute queries

3. Declaring and Using Variables and Constants

  1. Which keyword is used to declare a variable in PL/SQL?
    a) VAR
    b) DECLARE
    c) DIM
    d) TYPE
  2. Which data type can be used for declaring variables in PL/SQL?
    a) INTEGER
    b) VARCHAR
    c) DATE
    d) All of the above
  3. How do you assign a value to a variable in PL/SQL?
    a) SET variable = value;
    b) variable := value;
    c) variable = value;
    d) ASSIGN variable TO value;
  4. Which of the following is the correct syntax to declare a constant in PL/SQL?
    a) CONSTANT salary = 1000;
    b) constant salary NUMBER := 1000;
    c) salary constant = 1000;
    d) constant salary := 1000;
  5. In PL/SQL, which operator is used for assignment?
    a) =
    b) :=
    c) ->
    d) :=>

4. Control Structures (IF Statements, Loops)

  1. Which of the following is used for conditional branching in PL/SQL?
    a) IF statement
    b) FOR loop
    c) WHILE loop
    d) All of the above
  2. What will the following PL/SQL code do?
    IF salary > 1000 THEN
    salary := salary + 100;
    END IF;

    a) Increase salary by 100 if it is greater than 1000
    b) Decrease salary by 100 if it is greater than 1000
    c) Print an error if salary is greater than 1000
    d) None of the above
  3. Which of the following control structures in PL/SQL will execute a block of statements as long as a condition is true?
    a) IF
    b) FOR
    c) WHILE
    d) CASE
  4. Which type of loop will always execute at least once in PL/SQL?
    a) FOR loop
    b) WHILE loop
    c) LOOP
    d) EXIT loop
  5. Which keyword is used to exit from a loop in PL/SQL?
    a) BREAK
    b) EXIT
    c) CONTINUE
    d) STOP

5. Exception Handling

  1. Which section is used for exception handling in a PL/SQL block?
    a) BEGIN
    b) EXCEPTION
    c) HANDLING
    d) ERROR
  2. Which of the following is the correct way to handle an exception in PL/SQL?
    a) EXCEPTION WHEN exception_name THEN statement;
    b) WHEN exception_name THEN EXCEPTION statement;
    c) ERROR exception_name THEN EXCEPTION statement;
    d) EXCEPTION statement WHEN exception_name THEN;
  3. What does the RAISE statement do in PL/SQL?
    a) It raises a new exception
    b) It returns a value to the caller
    c) It ends a block
    d) It prints an error message
  4. Which built-in exception is raised for a division by zero in PL/SQL?
    a) NO_DATA_FOUND
    b) ZERO_DIVIDE
    c) DUP_VAL_ON_INDEX
    d) VALUE_ERROR
  5. Which exception is raised when no rows are returned for a SELECT INTO statement?
    a) NO_DATA_FOUND
    b) TOO_MANY_ROWS
    c) VALUE_ERROR
    d) INVALID_CURSOR
  6. What is the purpose of the WHEN OTHERS clause in exception handling?
    a) To handle specific exceptions
    b) To handle any exception that is not already handled
    c) To log errors
    d) To exit the PL/SQL block
  7. Which of the following can be used to log error information in PL/SQL?
    a) DBMS_OUTPUT.PUT_LINE
    b) EXCEPTION_LOGGING
    c) LOGGING_EXCEPTION
    d) DBMS_ERROR_LOG
  8. Which exception is raised when you attempt to insert duplicate values into a column that has a unique constraint?
    a) DUP_VAL_ON_INDEX
    b) NO_DATA_FOUND
    c) INVALID_CURSOR
    d) VALUE_ERROR
  9. Which PL/SQL statement is used to handle exceptions that occur in an anonymous block?
    a) EXCEPTION
    b) WHEN
    c) HANDLE
    d) RAISE
  10. What is the correct syntax for handling multiple exceptions in PL/SQL?
    a) EXCEPTION WHEN exception1 THEN statement1; WHEN exception2 THEN statement2;
    b) EXCEPTION WHEN exception1 THEN statement1 WHEN exception2 THEN statement2;
    c) EXCEPTION statement1 WHEN exception1 THEN statement2;
    d) EXCEPTION WHEN exception1 THEN statement1 WHEN exception2 THEN statement1;

Answer Table

QnoAnswer (Option with the text)
1b) Procedural programming
2a) BEGIN
3b) Procedural Language/SQL
4b) Oracle
5b) END;
6a) Declarations, Begin, and End
7a) Declarations, Begin, Exception, End
8c) Declarations, Begin, End
9a) Declarations
10c) To handle errors
11b) DECLARE
12d) All of the above
13b) variable := value;
14b) constant salary NUMBER := 1000;
15b) :=
16a) IF statement
17a) Increase salary by 100 if it is greater than 1000
18c) WHILE
19c) LOOP
20b) EXIT
21b) EXCEPTION
22a) EXCEPTION WHEN exception_name THEN statement;
23a) It raises a new exception
24b) ZERO_DIVIDE
25a) NO_DATA_FOUND
26b) To handle any exception that is not already handled
27a) DBMS_OUTPUT.PUT_LINE
28a) DUP_VAL_ON_INDEX
29a) EXCEPTION
30a) EXCEPTION WHEN exception1 THEN statement1; WHEN exception2 THEN statement2;

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top