The LET statement

With a LET statement, you can use one or more variable names with an equal (=) sign and a valid expression or function name. Each example in the following figure is a valid LET statement.
Figure 1: Valid LET statements.
LET a = 5;
LET b = 6; LET c = 10;
LET a,b = 10,c+d;
LET a,b = (SELECT cola,colb 
     FROM tab1 WHERE cola=10);
LET d = func1(x,y);

HCL OneDB™ allows you to assign a value to an opaque-type variable, a row-type variable, or a field of a row type. You can also return the value of an external function or another SPL function to an SPL variable.

Suppose you define the named row types zip_t and address_t, as Named and unnamed row variables. shows. Anytime you define a row-type variable, you must initialize the variable before you can use it. The following figure shows how you might define and initialize a row-type variable. You can use any row-type value to initialize the variable.
Figure 2: Define and initialize a row-type variable.
DEFINE a address_t;
LET a = ROW ('A Street', 'Nowhere', 'AA', 
         ROW(NULL, NULL))::address_t
After you define and initialize the row-type variable, you can write the LET statements that the following figure shows.
Figure 3: Write the LET statements.
LET a.zip.z_code = 32601;
LET a.zip.z_suffix = 4555;
   -- Assign values to the fields of address_t
Tip: Use dot notation in the form variable.field or variable.field.field to access the fields of a row type, as Handle row-type data describes.

Suppose you define an opaque-type point that contains two values that define a two-dimensional point, and the text representation of the values is '(x,y)'. You might also have a function circum() that calculates the circumference of a circle, given the point '(x,y)' and a radius r.

If you define an opaque-type center that defines a point as the center of a circle, and a function circum() that calculates the circumference of a circle, based on a point and the radius, you can write variable declarations for each. In the following figure, c is an opaque type variable and d holds the value that the external function circum() returns.
Figure 4: Writing variable declarations.
DEFINE c point;
DEFINE r REAL;
DEFINE d REAL;

LET c = '(29.9,1.0)' ;
   -- Assign a value to an opaque type variable

LET d = circum( c, r );
   -- Assign a value returned from circum()

The HCL OneDB Guide to SQL: Syntax describes in detail the syntax of the LET statement.