PL/SQL Questions and Answers – PL/SQL Syntax

This set of PL/SQL Multiple Choice Questions & Answers (MCQs) focuses on “PL/SQL Syntax”.

1. Which of the following syntax is correct way to declare a variable in PL/SQL?
a) datatype variable_name [NOT NULL := value ];
b) variable_name datatype [NOT NULL := value ];
c) variable_name datatype;
d) variable_name datatype (NOT NULL := value );
View Answer

Answer: b
Explanation: The correct way to declare a variable in PL/SQL is – variable_name

datatype [NOT NULL := VALUE];

Datatype is written after the variable name and the NOT NULL constraint and the value is optional in the declaration part of the variable.

advertisement
advertisement

2. Which of the following statement is used to initialise a variable in PL/SQL?
a) variable_name datatype := value;
b) datatype variable_name := value;
c) variable_name datatype = value;
d) datatype variable_name = value;
View Answer

Answer: a
Explanation: The statement which is used to initialise a variable in PL/SQL is –

variable_name datatype := VALUE;

The datatype is after the variable name and the value is assigned using := (assignment operator).

3. Which of the following statement is used to take input from the user in PL/SQL?
a) variable_name datatype = &variable_name;
b) datatype variable_name := &variable_name;
c) datatype variable_name = &variable_name;
d) variable_name datatype := &variable_name;
View Answer

Answer: d
Explanation: The statement which is used to take input from the user in PL/SQL is –

advertisement
variable_name datatype := &variable_name;

The assignment operator (:=) is followed by &variable_name to take input from the user.

advertisement

4. What will be the output of the following PL/SQL code?

SQL> SET SERVEROUTPUT ON; 
SQL> DECLARE 
    a varchar2(20) := 'Sanfoundry' ;  
BEGIN 
    dbms_output.put_line(a); 
END; 
/

a)

Sanfoundry
procedure successfully completed.

b)

PL/SQL procedure successfully completed.

c)

Sanfoundry
PL/SQL procedure successfully completed.

d)

Sanfoundry
View Answer
Answer: c
Explanation: The output of the following code is –

Sanfoundry
PL/SQL PROCEDURE successfully completed.

The statement PL/SQL procedure successfully completed is always printed after a successful compilation and execution of a PL/SQL code.

5. The slash (/) tells the SQL*Plus to execute the block written.
a) True
b) False
View Answer

Answer: a
Explanation: The slash (/) at the end of any Pl/SQL code block tells the SQL*Plus to execute the written block. SQL Plus is a Oracle Database utility, with a basic command-line interface, commonly used by users and administrators to administer a database.

Sanfoundry Global Education & Learning Series – PL/SQL.

To practice all areas of PL/SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.