Some Simple Statement Forms in PSM

Some Simple Statement Forms in PSM

Let us begin with a collection of statement forms that are easy to master.

1. The call-statement: The form of a procedure call is:

That is, the keyword CALL is followed by the name of the procedure and a parenthesized list of arguments, as in most any language. This call can,
however, be made from a variety of places:

i. From a host-language program, in which it might appear as

for example.

ii. As a statement of another PSM function or procedure.

iii. As an SQL command issued to the generic SQL interface. For instance, we can issue a statement such as

to such an interface, and have stored procedure Foo executed with its two parameters set equal to 1 and 3, respectively.

Note that, it is not permitted to call a function. You invoke functions in PSM as you do in C: use the function name and suitable arguments as part of an expression.

2. The return-statement: Its form is

This statement can only appear in a function. It evaluates the expression and sets the return-value of the function equal to that result. However, at variance with common programming languages, the return-statement of PSM does not end function. Rather, control continues with the following statement, and it is possible that the return-value will be changed before the function completes.

3. Declarations of local variables: The statement form

declares a variable with the given name to have the given type. This variable is local, and its value is not preserved by the DBMS after a running of the function or procedure. Declarations must precede executable statements in the function or procedure body.

4. Assignment Statements: The form of an assignment is:

Except for the introductory keyword SET, assignment in PSM is quite like assignment in other languages. The expression on the right of the equal-sign is evaluated, and its value becomes the value of the variable on the left. NULL is a permissible expression. The expression may even be a query, as long as it returns a single value.

5. Statement groups: We can form a list of statements ended by semicolons and surrounded by keywords BEGIN and END. This construct is treated as a single statement and can appear anywhere a single statement can. In particular, since a procedure or function body is expected to be a single statement, we can put any sequence of statements in the body by surrounding them by BEGIN. . .END.

6. Statement labels: We shall see in "Loops in PSM" one reason why certain statements need a label. We label a statement by prefixing it with a name (the label) and a colon.