Variables and data types

Top  Previous  Next

There are two types of variables, implicit and explicit variables.

 

Explicit variables

Explicit 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:

 

char(n)

Character string with a fixed length of n characters, padded by spaces if assigned a shorter value.

varchar(n)

Character string with a maximum length of n characters.

smallint

16 bit integer number, ranged -32768..32767

integer / int

32 bit integer number, ranged -2147483648..2147483647

bigint

64 bit integer number, ranged -2^63 through 2^63-1

float

Floating point number with approximately 7 digits after the decimal point

double precision

Floating point number with approximately 15 digits after the decimal point

numeric / decimal

Fixed point number

date

Date, without time

time

Time, without date

datetime / timestamp

Date & time combined

blob

Large binary string without logical maximum length

clob

Large character string without logical maximum length

 

Take note that the date/time values are implemented as floating point values internally.

 

Implicit variables

When 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.

 

datatypes_date_example

Strong typed explicit variables and untyped implicit variables with the same values