DB2 Version 10.1 for Linux, UNIX, and Windows

Assignment statement (PL/SQL)

The assignment statement sets a previously-declared variable or formal OUT or IN OUT parameter to the value of an expression.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-variable--:=--expression------------------------------------><

Description

variable
Specifies an identifier for a previously-declared variable, OUT formal parameter, or IN OUT formal parameter.
expression
Specifies an expression that evaluates to a single value. The data type of this value must be compatible with the data type of variable.

Example

The following example shows assignment statements in the executable section of a procedure:
CREATE OR REPLACE PROCEDURE dept_salary_rpt (
    p_deptno       IN   NUMBER,
    p_base_annual  OUT  NUMBER
)
IS
    todays_date     DATE;
    rpt_title       VARCHAR2(60);
    base_sal        INTEGER;
    base_comm_rate  NUMBER;
BEGIN
    todays_date := SYSDATE;
    rpt_title := 'Report For Department # ' || p_deptno || ' on '
        || todays_date;
    base_sal := 35525;
    base_comm_rate := 1.33333;
    p_base_annual := ROUND(base_sal * base_comm_rate, 2);

    DBMS_OUTPUT.PUT_LINE(rpt_title);
    DBMS_OUTPUT.PUT_LINE('Base Annual Salary: ' || p_base_annual);
END
/