PL/SQL Questions and Answers – PL/SQL Arrays

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

1. In PL/SQL, which of the following data-structure can be used to store a fixed number of elements of same datatype?
a) ARRAY
b) NARRAY
c) VARRAY
d) CARRAY
View Answer

Answer: c
Explanation: In PL/SQL, the VARRAY data structure can be used to store a fixed number of elements of same datatype to form an array. It is used to store an ordered collection of data.

2. Which of the following is the correct basic syntax for creating a VARRAY type within a PL/SQL block?
a) TYPE varray_name IS VARRAY(n) <element_type>
b) TYPE varray_name IS VARRAY(n) of <element_type>
c) TYPE varray_name VARRAY(n) of <element_type>
d) varray_name IS VARRAY(n) of <element_type>
View Answer

Answer: b
Explanation: The correct basic syntax for creating a VARRAY type within a PL/SQL block is –

TYPE varray_name IS VARRAY(n) OF <element_type>

Where, varray_name is a valid identifier name.
n is the maximum number of elements in the array.
<element_type> is the datatype of elements in the array.

advertisement
advertisement

3. What is the index number for the starting element in VARRAY?
a) 0
b) 1
c) -1
d) 2
View Answer

Answer: b
Explanation: In PL/SQL, the starting element in the VARRAY has an index number of 1 which is different from the usual starting index number of array i.e. 0.

4. Which of the following command can be used to change the maximum size of a VARRAY?
a) ALTER TYPE
b) ALTER VARRAY
c) ALTER ARRAY
d) Maximum size of a VARRAY cannot be changed
View Answer

Answer: a
Explanation: The ALTER TYPE command can be used to change the maximum size of a VARRAY. It’s syntax is –

ALTERTYPE varray_name IS VARRAY(n) OF <element_type>

5. Arrays in other languages becomes VARRAYS in PL/SQL.
a) True
b) False
View Answer

Answer: a
Explanation: The concept of arrays in other languages is the same as of VARRAY in PL/SQL. The only difference that comes is in the starting index number which is 0 for arrays and 1 for VARRAY.
advertisement

Sanfoundry Global Education & Learning Series – PL/SQL.

advertisement

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

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.