PREPARE
Syntax
1136
CLIENT_MULTI_STATEMENTS
(which also enables
CLIENT_MULTI_RESULTS
). For additional
information, see
Section 13.2.1, “
CALL
Syntax”
.
13.5.1.
PREPARE
Syntax
PREPARE
stmt_name
FROM
preparable_stmt
The
PREPARE
statement prepares a SQL statement and assigns it a name,
stmt_name
, by which
to refer to the statement later. The prepared statement is executed with
EXECUTE
and released with
DEALLOCATE PREPARE
. For examples, see
Section 13.5, “SQL Syntax for Prepared Statements”
.
Statement names are not case sensitive.
preparable_stmt
is either a string literal or a user variable
that contains the text of the SQL statement. The text must represent a single statement, not multiple
statements. Within the statement,
?
characters can be used as parameter markers to indicate where
data values are to be bound to the query later when you execute it. The
?
characters should not be
enclosed within quotation marks, even if you intend to bind them to string values. Parameter markers
can be used only where data values should appear, not for SQL keywords, identifiers, and so forth.
If a prepared statement with the given name already exists, it is deallocated implicitly before the new
statement is prepared. This means that if the new statement contains an error and cannot be prepared,
an error is returned and no statement with the given name exists.
The scope of a prepared statement is the session within which it is created, which as several
implications:
• A prepared statement created in one session is not available to other sessions.
• When a session ends, whether normally or abnormally, its prepared statements no longer exist.
If auto-reconnect is enabled, the client is not notified that the connection was lost. For this
reason, clients may wish to disable auto-reconnect. See
Section 20.6.14, “Controlling Automatic
Reconnection Behavior”
.
• A prepared statement created within a stored program continues to exist after the program finishes
executing and can be executed outside the program later.
• A statement prepared in stored program context cannot refer to stored procedure or function
parameters or local variables because they go out of scope when the program ends and would be
unavailable were the statement to be executed later outside the program. As a workaround, refer
instead to user-defined variables, which also have session scope; see
Section 9.4, “User-Defined
Variables”
.
13.5.2.
EXECUTE
Syntax
EXECUTE
stmt_name
[USING @
var_name
[, @
var_name
] ...]
After preparing a statement with
PREPARE
, you execute it with an
EXECUTE
statement that refers to
the prepared statement name. If the prepared statement contains any parameter markers, you must
supply a
USING
clause that lists user variables containing the values to be bound to the parameters.
Parameter values can be supplied only by user variables, and the
USING
clause must name exactly as
many variables as the number of parameter markers in the statement.
You can execute a given prepared statement multiple times, passing different variables to it or setting
the variables to different values before each execution.
For examples, see
Section 13.5, “SQL Syntax for Prepared Statements”
.
13.5.3.
DEALLOCATE PREPARE
Syntax
{DEALLOCATE | DROP} PREPARE
stmt_name
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...