PL/SQL Questions and Answers – PL/SQL Variables

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

1. Which of the following variable name is valid in PL/SQL?
a) _person123
b) person
c) person@123
d) 11person
View Answer

Answer: b
Explanation: The name of a PL/SQL variable should start with a letter, optionally followed by letters, numerals, dollar signs and underscores.

2. Which of the following is an incorrect variable declaration in PL/SQL?
a) var_number varchar2(10);
b) var_text number (10);
c) var_char char (1) := ‘Y’;
d) var_text varchar2(10) := ‘hello world’;
View Answer

Answer: d
Explanation: The incorrect variable declaration is – var_text varchar2(10) := ‘hello world’;
As the “hello world” string exceeds the word limit of 10 characters while declaring the variable.

3. Which of the following is not a valid variable type in PL/SQL?
a) VARCHAR1
b) VARCHAR2
c) CHAR
d) NUMBER
View Answer

Answer: a
Explanation: There is no variable type named VARCHAR1 in PL/SQL. VARCHAR2 is used to store strings. CHAR is used to store single character and NUMBER is used to store numeric values in variables.
advertisement
advertisement

4. Which of the following is the DEFAULT value of an uninitialized variable in PL/SQL?
a) 0
b) /0
c) NULL
d) \0
View Answer

Answer: c
Explanation: Whenever we declare a variable, PL/SQL assigns it a default value of NULL. If we want to initialize a variable with a value other than the NULL value then we can do it by using the assignment operator or the DEFAULT keyword during the variable’s declaration.

5. Which of the following variable is declared in the outermost block or package of PL/SQL?
a) Local Variable
b) Global Variable
c) Reference Variable
d) Static Variable
View Answer

Answer: b
Explanation: Global variables are the variables that are declared in the outermost block or a package and can be accessible to the whole package. Local variables are the variables that are declared in an inner block and are not accessible to outer blocks.

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

DECLARE 
   a INTEGER := 30; 
   b INTEGER := 40; 
   c INTEGER; 
   d REAL; 
BEGIN 
   c := a + b; 
   dbms_output.put_line('Value of c: ' || c); 
   d := 70.0/3.0; 
   dbms_output.put_line('Value of d: ' || d); 
END; 
/

a)

advertisement
VALUE OF c: 70 
VALUE OF d: 23.333333333333333333

b)

advertisement
VALUE OF c: 70 
VALUE OF d: 23.333333333333333333  
PL/SQL PROCEDURE successfully completed.

c)

VALUE OF c: 70
VALUE OF d: 23  
PL/SQL PROCEDURE successfully completed.

d)

VALUE OF c: 70.000000000000000000
VALUE OF d: 23.333333333333333333  
PL/SQL PROCEDURE successfully completed.
View Answer
Answer: b
Explanation: The correct output of the given code would be –

VALUE OF c: 70 
VALUE OF d: 23.333333333333333333
PL/SQL PROCEDURE successfully completed.

After every successful PL/SQL code execution, “PL/SQL procedure successfully completed” is printed. Since, d has real as it’s datatype so it will return the output in decimal form.

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.