Handling Row Types
In an SPL routine, you can use named row types and unnamed row types as parameter definitions, arguments, variable definitions, and return values. For information about how to declare a row variable in SPL, see "Declaring Row-Type Variables".
Figure 14-94 defines a row type salary_t and an emp_info table, which are the examples that this section uses.
The emp_info table has columns for the employee name and salary information.
Updating a Row-Type Column
From within an SPL routine, you can use a row variable to update a row type or specific fields of a row type. Figure 14-95 shows an SPL procedure that increases the base salary of an employee. The procedure retrieves data stored in the form of a row type and updates salary column of the emp_info table.
Figure 14-95
The SELECT statement selects one row from the salary column of emp_info table into the row variable row_var.
The procedure of Figure 14-95 uses SPL dot notation to directly access the base and bonus fields of the variable row_var. In this case, the dot notation means variable.field. The procedure recalculates the value of row_var.base as
(row.var * pct) and the new value is used to update the salary column of the emp_info table.
Precedence of Dot Notation
With Universal Server a value that uses dot notation (as in proj.name) in an SQL statement in an SPL routine has one of three meanings, in the following order:
1. variable.field
2. column.field
3. table.column
In other words, the expression proj.name is first evaluated as variable.field. If the routine does not find a variable proj, it evaluates the expression as column.field. If the routine does not find a column proj, it evaluates the expression as table.column.
|