content_image/787279.jpg
it results in an error. If too many prepared statements are created and not deallocated by either the DEALLOCATE PREPARE  statement or the end of the session, you might encounter the upper limit enforced by the max_prepared_stmt_count  system variable. 

## 13.6 Compound Statement Syntax 

For examples, see Section 13.5, “Prepared Statements” . 

This section describes the syntax for the BEGIN ... END  compound statement and other statements that can be used in the body of stored programs: Stored procedures and functions, triggers, and events. These objects are defined in terms of SQL code that is stored on the server for later invocation (see Chapter 25, Stored Objects ). 

A compound statement is a block that can contain other blocks; declarations for variables, condition handlers, and cursors; and flow control constructs such as loops and conditional tests. 

## 13.6.1 BEGIN ... END Compound Statement 

[ begin_label :] BEGIN [ statement_list ] END [ end_label ] 

BEGIN ... END  syntax is used for writing compound statements, which can appear within stored programs (stored procedures and functions, triggers, and events). A compound statement can contain multiple statements, enclosed by the BEGIN  and END  keywords. statement_list  represents a list of one or more statements, each terminated by a semicolon ( ; ) statement delimiter. The statement_list  itself is optional, so the empty compound statement ( BEGIN END ) is legal. 

BEGIN ... END  blocks can be nested. 

Use of multiple statements requires that a client is able to send statement strings containing the ; statement delimiter. In the mysql  command-line client, this is handled with the delimiter  command. Changing the ;  end-of-statement delimiter (for example, to // ) permit ;  to be used in a program body. For an example, see Section 25.1, “Defining Stored Programs” . 

A BEGIN ... END  block can be labeled. See Section 13.6.2, “Statement Labels” . 

The optional [NOT] ATOMIC  clause is not supported. This means that no transactional savepoint is set at the start of the instruction block and the BEGIN  clause used in this context has no effect on the current transaction. 

## 13.6.2 Statement Labels 

<img src='content_image/787279.jpg'>

[ begin_label :] BEGIN [ statement_list ] END [ end_label ] [ begin_label :] LOOP statement_list END LOOP [ end_label ] 

## Note 

Within all stored programs, the parser treats BEGIN [WORK]  as the beginning of a BEGIN ... END  block. To begin a transaction in this context, use START TRANSACTION  instead. 

