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
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
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.
3. What is the index number for the starting element in VARRAY?
a) 0
b) 1
c) -1
d) 2
View Answer
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
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
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.
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.