Variables in BSQL
Host variables are used in SQL statements to pass values between the database and an application program, see the Mimer SQL Programmer's Manual.
Host variable syntax is also supported in BSQL to facilitate interactive design and testing of SQL statements intended for use in SQL application programs.
In BSQL, host variables serve as parameter markers, and the user is prompted for parameter values when the statement is executed.
You can use host variables used to:
- assign values to columns in the database (
- to manipulate information taken from the database or contained in other variables (in expressions)
- to provide values for comparison predicates.
In all these contexts, the data type and length of the host variable must be compatible with that of any database values within the same syntax unit.
Writing Host Variables in SQL
Host variables are written in SQL as::host-identifier
or:host-identifier INDICATOR :indicator-identifier
In the first construction, the host identifier is the name of the main host variable.
In the second and third constructions, the main variable host-identifier is associated with an indicator variable indicator-identifier, used to signal the assignment of a null value to the main variable.
See the Mimer SQL Programmer's Manual for a description of the use of indicator variables.
Scope of Host Variables
The scope of host variables in BSQL is restricted to the individual usage instance in each statement.
Variables may not be used to pass values between separate statements, and the same variable name used more than once in a statement represents separate, independent variables.
Using Host Variables
When host variables are used in BSQL, BSQL prompts for the variable values, for example:SQL>SELECT * FROM countries WHERE country = :COUNTRY; COUNTRY: Spain
This corresponds to the statement:SQL>SELECT * FROM countries WHERE country = 'Spain';
Note: The entered variable is not enclosed between single quotation marks, in contrast to the corresponding string value.
Variables enclosed in single quotation marks will be interpreted as literal strings.
Including Indicator Variables
If an indicator variable is included, you will be prompted for whether to use a null value.
If you answer the prompt with
No, you will then be prompted for a value.
If you answer
Yes, the null value will be used. For example:SQL>UPDATE currencies SET exchange_rate = :RATE:IND SQL& WHERE code = 'BND'; Null ?n RATE: 1.34 SQL>UPDATE currencies SET exchange_rate = :RATE:IND SQL& WHERE code = 'BND'; Null ?y
In the first example above, the
exchange_ratevalue is updated to 1.34. In the second example, the
exchange_ratevalue is set to null.
Note: The prompts appear in the order in which the variables are used in the statement.
Mimer Information Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40