query_script_var

var: declaration of QueryScript local variables

SYNOPSIS

var $variable1 [, $variable2 ...];
var $single_var := 'some_value';
while(expression)
{
  var $variable3 [, $variable4 ...];
  var $pi := PI();
}

DESCRIPTION

var is a QueryScript statement which declares local variables.

var can appear anywhere within a script: within loops, if-else clauses, in general scope or in sub statement blocks.

Variables declared by var are only visible at the scope in which they're declared. A local variable is known to be NULL at point of declaration, and is cleared once out of scope (being reassigned as NULL).

var allows for two types of variable declaration:

  • One or more variables, comma delimited. These variables are assigned with NULL.
  • A single variable with assignment, as in var $area := PI() * POW($r, 2). The assigned value can be of any valid expression.
It is an error to re-declare a local variable within a script, regardless of scope.

EXAMPLES

Declare variabels at different levels:

var $a, $b;
set $a := 4, $b := 17;
var $c := $a;
while ($c > 0)
{
  var $d := $c - 1;
  set $c := $c - 1;
}
set $b := $c;

SEE ALSO

Variables, input

AUTHOR

Shlomi Noach
 
common_schema documentation