Rechercher dans le manuel MySQL
24.1 Defining Stored Programs
Each stored program contains a body that consists of an SQL
statement. This statement may be a compound statement made up of
several statements separated by semicolon (;
)
characters. For example, the following stored procedure has a body
made up of a BEGIN ...
END
block that contains a
SET
statement and a REPEAT
loop that
itself contains another
SET
statement:
- END;
If you use the mysql client program to define a stored program containing semicolon characters, a problem arises. By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.
To redefine the mysql delimiter, use the
delimiter
command. The following example shows
how to do this for the dorepeat()
procedure
just shown. The delimiter is changed to //
to
enable the entire definition to be passed to the server as a
single statement, and then restored to ;
before
invoking the procedure. This enables the ;
delimiter used in the procedure body to be passed through to the
server rather than being interpreted by mysql
itself.
You can redefine the delimiter to a string other than
//
, and the delimiter can consist of a single
character or multiple characters. You should avoid the use of the
backslash (\
) character because that is the
escape character for MySQL.
The following is an example of a function that takes a parameter,
performs an operation using an SQL function, and returns the
result. In this case, it is unnecessary to use
delimiter
because the function definition
contains no internal ;
statement delimiters:
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-stored-programs-defining.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.