CLOSE
cursor_name
This statement closes a previously opened cursor. For an example, see
An error occurs if the cursor is not open.
If not closed explicitly, a cursor is closed at the end of the
declared.
13.6.6.2. Cursor
DECLARE
DECLARE
cursor_name
This statement declares a cursor and associates it with a
be traversed by the cursor. To fetch the rows later, use a
retrieved by the
statement.
The
SELECT
Cursor declarations must appear before handler declarations and after variable and condition
declarations.
A stored program may contain multiple cursor declarations, but each cursor declared in a given block
must have a unique name. For an example, see
For information available through
information by using a cursor with an
13.6.6.3. Cursor
FETCH
FETCH [[NEXT] FROM]
This statement fetches the next row for the
(which must be open), and advances the cursor pointer. If a row exists, the fetched columns are stored
in the named variables. The number of columns retrieved by the
number of output variables specified in the
If no more rows are available, a No Data condition occurs with SQLSTATE value '02000'. To detect
this condition, you can set up a handler for it (or for a
Section 13.6.6,
13.6.6.4. Cursor
OPEN
OPEN
cursor_name
This statement opens a previously declared cursor. For an example, see
13.6.7. Condition Handling
Conditions may arise during stored program execution that require special handling, such as exiting the
current program block or continuing execution. Handlers can be defined for general conditions such as
warnings or exceptions, or for specific conditions such as a particular error code. Specific conditions
can be assigned names and referred to that way in handlers.
To name a condition, use the
DECLARE ... HANDLER
Section 13.6.7.2,
Other statements related to conditions are SIGNAL, RESIGNAL, and
and
RESIGNAL
not supported until MySQL 5.6.
Syntax
CURSOR FOR
select_statement
statement must match the number of output variables specified in the
SELECT
statement cannot have an
SHOW
Syntax
cursor_name
INTO
"Cursors".
Syntax
DECLARE ... CONDITION
statement. See
"DECLARE ... HANDLER
statements are not supported until MySQL 5.5. The
Condition Handling
BEGIN ... END
SELECT
FETCH
clause.
INTO
Section 13.6.6,
statements, it is possible in many cases to obtain equivalent
INFORMATION_SCHEMA
var_name
[, var_name] ...
statement associated with the specified cursor
SELECT
statement.
FETCH
NOT FOUND
statement. To declare a handler, use the
Section 13.6.7.1,
Syntax".
1145
Section 13.6.6,
block in which it was
statement that retrieves the rows to
statement. The number of columns
"Cursors".
table.
statement must match the
SELECT
condition). For an example, see
Section 13.6.6,
"DECLARE ... CONDITION
DIAGNOSTICS. The
GET
GET DIAGNOSTICS
"Cursors".
FETCH
"Cursors".
Syntax", and
SIGNAL
statement is
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers