18.8. Invoking Stored Routines


We have already covered the concept of invoking stored routines earlier in the course of this discussion, but just to make it explicit, here are the rules:

  • To invoke a procedure, use a CALL statement. This is a separate statement; a procedure cannot be invoked as part of an expression. Suppose that the rect_area() procedure has this definition:

     CREATE PROCEDURE rect_area (width INT, height INT)   SELECT width * height AS area; 

    The procedure is invoked with CALL as follows:

     mysql> CALL rect_area(10,25); +------+ | area | +------+ |  250 | +------+ 1 row in set (0.00 sec) 

    If the procedure has OUT or INOUT parameters, the procedure can pass back values to its caller through these parameters.

  • To invoke a function, invoke it in an expression. It returns a single value that is used in evaluating the expression, just as for a built-in function. Suppose that the circle_area() function has this definition:

     CREATE FUNCTION circle_area (radius FLOAT)   RETURNS FLOAT   RETURN PI() * radius * radius; 

    The function is invoked in an expression as follows:

     mysql> SELECT circle_area(10); +-----------------+ | circle_area(10) | +-----------------+ | 314.15927124023 | +-----------------+ 1 row in set (0.00 sec) 



MySQL 5 Certification Study Guide
MySQL 5.0 Certification Study Guide
ISBN: 0672328127
EAN: 2147483647
Year: 2006
Pages: 312

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net