Defining Stored Programs •Stored programs include stored routines, triggers, and events. •Stored objects include stored programs and views. This chapter describes how to use stored objects. The following sections provide additional information about SQL syntax for statements related to these objects, and about object processing: •For each object type, there are  CREATE ,  ALTER , and  DROP  statements that control which objects exist and how they are defined. See Section 13.1, “Data Definition Statements” . •The  CALL  statement is used to invoke stored procedures. See Section 13.2.1, “CALL Statement” . •Stored program definitions include a body that may use compound statements, loops, conditionals, and declared variables. See Section 13.6, “Compound Statement Syntax” . •Metadata changes to objects referred to by stored programs are detected and cause automatic reparsing of the affected statements when the program is next executed. For more information, see Section 8.10.3, “Caching of Prepared Statements and Stored Programs” . 25.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: CREATE PROCEDURE dorepeat(p1 INT) BEGIN SET @x = 0; REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT; 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. 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 | 4728