5. Embedded SQL for Ada : Ada Variables and Data Types : Variable Usage
 
Share this page                  
Variable Usage
Ada variables declared to Embedded SQL can substitute for many non key-word elements of Embedded SQL statements. Of course, the variable and its data type must make sense in the context of the element. When you use an Ada variable (or named constant) in an Embedded SQL statement, you must precede it with a colon. You must further verify that the statement using the variable is in the scope of the variable's declaration. As an example, the following select statement uses the variables "namevar" and "numvar" to receive data, and the variable "idnovar" as an expression in the where clause:
exec sql select name, num
        into :namevar, :numvar
        from employee
        where idno = :idnovar;
When referencing a variable, you cannot use an Ada attribute, because the attribute is introduced by a single quote. Embedded SQL treats this single quote as the beginning of a string literal and generates a syntax error.
Various rules and restrictions apply to the use of Ada variables in Embedded SQL statements. The sections below describe the usage syntax of different categories of variables and provide examples of such use.