END;
If you use the
problem arises. By default,
must redefine the delimiter temporarily to cause
the server.
To redefine the
do this for the
definition to be passed to the server as a single statement, and then restored to
procedure. This enables the
rather than being interpreted by
mysql>
delimiter //
mysql>
CREATE PROCEDURE dorepeat(p1 INT)
->
BEGIN
->
SET @x = 0;
->
REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
->
END
->
//
Query OK, 0 rows affected (0.00 sec)
mysql>
delimiter ;
mysql>
CALL dorepeat(1000);
Query OK, 0 rows affected (0.00 sec)
mysql>
SELECT @x;
+------+
| @x
|
+------+
| 1001 |
+------+
1 row in set (0.00 sec)
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
definition contains no internal
mysql>
CREATE FUNCTION hello (s CHAR(20))
mysql>
RETURNS CHAR(50) DETERMINISTIC
->
RETURN CONCAT('Hello, ',s,'!');
Query OK, 0 rows affected (0.00 sec)
mysql>
SELECT hello('world');
+----------------+
| hello('world') |
+----------------+
| Hello, world!
+----------------+
1 row in set (0.00 sec)
18.2. Using Stored Routines (Procedures and Functions)
Stored routines (procedures and functions) are supported in MySQL 5.0. A stored routine is a set of
SQL statements that can be stored in the server. Once this has been done, clients don't need to keep
reissuing the individual statements but can refer to the stored routine instead.
Stored routines require the
5.0 installation procedure. If you are upgrading to MySQL 5.0 from an earlier version, be sure to update
your grant tables to make sure that the
Check Tables for MySQL
Using Stored Routines (Procedures and Functions)
client program to define a stored program containing semicolon characters, a
mysql
itself recognizes the semicolon as a statement delimiter, so you
mysql
delimiter, use the
mysql
procedure just shown. The delimiter is changed to
dorepeat()
delimiter used in the procedure body to be passed through to the server
;
mysql
statement delimiters:
;
|
table in the
proc
Upgrade".
to pass the entire stored program definition to
mysql
command. The following example shows how to
delimiter
itself.
database. This table is created during the MySQL
mysql
table exists. See
proc
1694
to enable the entire
//
before invoking the
;
because the function
delimiter
Section 4.4.9,
"mysql_upgrade
—
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers