Most stored programs involve some kind of interaction with database tables. There are four main types of interactions:
Store the results of a SQL statement that returns a single row into local variables.
Create a “cursor” that allows the stored program to iterate through the rows returned by a SQL statement.
Execute a SQL statement, returning the result set(s) to the calling program.
Embed a SQL statement that does not return a result set,
The following sections look briefly at each type of interaction.
To run the examples in this section of the chapter, you should install the book’s sample database, available at this book’s web site (see the Preface for details).
SELECT INTO syntax
when you are querying information from a single row of data (whether
retrieved from a single row, an aggregate of many rows, or a join of
multiple tables). In this case, you include an
INTO clause “inside” the
SELECT statement that tells MySQL where to
put the data retrieved by the query.
mysql> CALL ...