Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

Returning multiple result sets from procedures Next Page

Returning variable result sets from procedures

The RESULT clause is optional in procedures. Omitting the result clause allows you to write procedures that return different result sets, with different numbers or types of columns, depending on how they are executed.

If you do not use the variable result sets feature, you should use a RESULT clause for performance reasons.

For example, the following procedure returns two columns if the input variable is Y, but only one column otherwise:

CREATE PROCEDURE Names( IN formal char(1) )
   IF formal = 'y' THEN
      SELECT Surname, GivenName
      FROM Employees
      SELECT GivenName
      FROM Employees

The use of variable result sets in procedures is subject to some limitations, depending on the interface used by the client application.