It might be tempting to open the book table on its Structure page and
look there for a list of procedures that manipulate this table, like our add_
page() procedure. However, all procedures are stored at the database
level, and there is no direct link between the code itself (UPDATE book)
and the place where the procedure is stored.
Manually Creating a Function
Functions are similar to stored procedures. However, a function may return just one
value, whereas a stored procedure can have more than one OUT parameter. On the
other hand, using a stored function from within a SELECT statement may seem more
natural and avoids the need of an intermediate SQL variable to hold the value of an
OUT parameter.
What is the goal of functions? As an example, a function can be used to calculate
the total cost of an order, including tax and shipping. Putting this logic inside the
database, instead of at the application level, helps to document the applicationdatabase
interface and avoids duplicating business logic in every application that
needs to deal with this logic.
We should not confuse MySQL 5.0's functions with UDF (User-Defined Functions),
which existed before MySQL 5.0. A UDF is constituted of code written in C or C++,
compiled into a shared object, and referenced with a CREATE FUNCTION statement
plus the SONAME keyword.
Pages:
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251