5. Embedded SQL for Ada : Ada Variables and Data Types : Variable Usage : Array Variables
 
Share this page                  
Array Variables
An array variable is referred to by the syntax:
:arrayname(subscript{,subscript})
Syntax Notes:
You must subscript the variable because only scalar-valued elements (integers, floating-point, and character strings) are legal Embedded SQL values.
When you declare the array, the Embedded SQL preprocessor does not parse the array bounds specification. Consequently, the preprocessor accepts illegal bounds values. Also, when you reference an array, the subscript is not parsed, allowing you to use illegal subscripts. The preprocessor only confirms that you used an array subscript for an array variable. You must make sure that the subscript is legal and that you used the correct number of indices.
A character string variable is not an array and cannot be subscripted in order to reference a single character or a slice of the string. For example, if the following variable were declared:
abc: String(1..3) := "abc";
you could not reference
:abc(1)
to access the character "a". To perform such a task, you should declare the variable as an array of three one-character long strings:
abc: array(1..3) of String(1..1) := ("a","b","c");
Note that you can only declare variables of the Ada character type as a one-dimensional array. When you use a variable of that type, you must not subscript it.
Arrays of null indicator variables used with record assignments should not include subscripts when referenced.
In the following example, the loop variable "i" is used as a subscript and need not be declared to Embedded SQL, as it is not parsed.
exec sql begin declare section;
        formnames: array(1..3) of String(1..8);
exec sql end declare section;
    ...

for i in 1..3 loop
        exec frs forminit :formnames(i);
end loop;