PREPAREstmt_name
FROMpreparable_stmt
The PREPARE
statement prepares a
statement and assigns it a name,
stmt_name
, by which to refer to the
statement later. Statement names are not case sensitive.
preparable_stmt
is either a string
literal or a user variable that contains the text of the
statement. The text must represent a single SQL 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.
A prepared statement is executed with
EXECUTE
and released with
DEALLOCATE PREPARE
.
The scope of a prepared statement is the session within which it is created. Other sessions cannot see it.
For examples, see Section 12.6, “SQL Syntax for Prepared Statements”.