The SET statement allows you to assign values for variables. The following syntax is supported for the assignment statement:

SET (<variable_name> = <expression> | (<variable_name>[, ...]) = <select_statement>)

where:

variable_name
is the name of the variable to which you want to assign a value.
expression
are the variables, operators, literals, and method calls used to compute a value for the variable.
select_statement
(optional) is the syntax of a SELECT statement used to return the value of the variable.

For example, in the following statement, the expression is evaluated and the result is placed for the example variable..

CREATE FUNCTION squared(n INTEGER) RETURNS INTEGER
    BEGIN ATOMIC
    DECLARE example INTEGER;
    SET example = n * n;
    RETURN example;
END

In this statement, the SELECT statement is used to return zero or one rows. If no rows are returned, no assignment is made. However, if it returns one row, each column in the result is assigned to the corresponding named variable. If more than one row is returned, an exception is raised.

CREATE PROCEDURE get_eldest_child(IN id BIGINT, OUT name VARCHAR(32), OUT age INTEGER)
    READS SQL DATA
    BEGIN ATOMIC
    SET (name, age) = (SELECT TOP 1 firstname, (CURRENT_DATE - dob) YEAR FROM people ORDER BY dob DESC);
END