Variables and data types |
Top Previous Next |
There are two types of variables, implicit and explicit variables.
Explicit variablesExplicit variables are declared with a given data type and possibly initialized with a default value, or NULL if no default value has been specified.
The code below has 3 explicit variables: 1 input parameter, 1 output parameter and 1 declared local variable.
execute udsblock(vc1 varchar(10)) returns(o1 integer) as declare variable b integer = 0; begin o1 = iif(vc1 <> '', 2, 1); /*o1 = iif('' <> '', 2, 1); */ end
The following data types are available for variables and parameters:
Take note that the date/time values are implemented as floating point values internally.
Implicit variablesWhen you don't declare a variable, but you use them anyway, this is called an implicit variable. These have no specific data type assigned, so displaying the value might be tricky, especially with date/time values.
execute UDSBlock as declare DValue2 date; /* strong typed */ declare DTValue2 timestamp; /* strong typed */ declare TValue2 time; /* strong typed */ begin /* uses an implicitly created variable */ DValue = Util.Date();
/* uses a strong typed declared variable */ DValue2 = Util.Date();
DTValue = Util.Now(); DTValue2 = Util.Now();
TValue = Util.Time(); TValue2 = Util.Time(); end
In this block, DValue is an implicit variable and has no type, while DValue2 is explicitly declared and strong typed. This means that DValue2 will always behave like a date data type, while DValue is set to a floating point without a data type specification so it's unknown that it represents a date.
Strong typed explicit variables and untyped implicit variables with the same values
|