0% found this document useful (0 votes)
32 views1 page

PLSQL Array

PL/SQL provides a data structure called a VARRAY that can store a fixed number of elements of the same type in a sequential collection. A VARRAY is used to store ordered data and can be thought of as a collection of variables of the same type. All elements in a VARRAY are stored in contiguous memory locations from lowest to highest. VARRAYs are declared using the TYPE keyword and specify the maximum number of elements and their type. An example demonstrates declaring name and grade VARRAYs, populating them, counting the number of elements, and outputting the names and grades.

Uploaded by

letogi7085
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

PLSQL Array

PL/SQL provides a data structure called a VARRAY that can store a fixed number of elements of the same type in a sequential collection. A VARRAY is used to store ordered data and can be thought of as a collection of variables of the same type. All elements in a VARRAY are stored in contiguous memory locations from lowest to highest. VARRAYs are declared using the TYPE keyword and specify the maximum number of elements and their type. An example demonstrates declaring name and grade VARRAYs, populating them, counting the number of elements, and outputting the names and grades.

Uploaded by

letogi7085
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

PL/SQL ARRAY

The PL/SQL programming language provides a data structure called the VARRAY, which can store a
fixed-size sequential collection of elements of the same type. A varray is used to store an ordered
collection of data, however it is often better to think of an array as a collection of variables of the same
type.
All varrays consist of contiguous memory locations. The lowest address corresponds to the first
element and the highest address to the last element.

An array is a part of collection type data and it stands for variable-size arrays.

SYNTAX: −

TYPE varray_type_name IS VARRAY(n) of <element_type>

For example −

TYPE namearray IS VARRAY(5) OF VARCHAR2(10);

Type grades IS VARRAY(5) OF INTEGER;

Example:

SQL> set serveroutput on


SQL> DECLARE Output:
type namesarray IS VARRAY(5) OF
VARCHAR2(10); Total 5 Students
type grades IS VARRAY(5) OF INTEGER; Student: Kavita
names namesarray; Marks: 98
marks grades; Student: Pritam
total integer; Marks: 97
BEGIN Student: Ayan
names := namesarray('Kavita', 'Pritam', 'Ayan', Marks: 78
'Rishav', 'Aziz'); Student: Rishav
marks:= grades(98, 97, 78, 87, 92); Marks: 87
total := names.count; Student: Aziz
dbms_output.put_line('Total '|| total || ' Marks: 92
Students');
FOR i in 1 .. total LOOP PL/SQL procedure successfully completed.
dbms_output.put_line('Student: ' || names(i) ||
' SQL>
Marks: ' || marks(i));
END LOOP;
END;
/

You might also like