Bug #15809 | DECLARING cursors inside IF statement doesn't work without BEGIN...END | ||
---|---|---|---|
Submitted: | 16 Dec 2005 9:59 | Modified: | 16 Dec 2005 11:56 |
Reporter: | Gleb Paharenko | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S3 (Non-critical) |
Version: | 5.0.16 | OS: | Linux (Linux) |
Assigned to: | CPU Architecture: | Any |
[16 Dec 2005 9:59]
Gleb Paharenko
[16 Dec 2005 11:56]
Valeriy Kravchuk
Thank you for a problem report. Sorry, but I do not think it is a bug. The problem is that cursor should be declared, and all declarations are at the beggining of SP or a block. Please, read (http://dev.mysql.com/doc/refman/5.0/en/cursors.html): "Cursors must be declared before declaring handlers, and variables and conditions must be declared before declaring either cursors or handlers." And, even more clearly (http://dev.mysql.com/doc/refman/5.0/en/declare.html): "The DECLARE statement is used to define various items local to a routine: local variables (see Section 17.2.9, “Variables in Stored Procedures”), conditions and handlers (see Section 17.2.10, “Conditions and Handlers”) and cursors (see Section 17.2.11, “Cursors”). SIGNAL and RESIGNAL statements are not currently supported. DECLARE may be used only inside a BEGIN ... END compound statement and must be at its start, before any other statements." So, it is not a bug, but a documented behaviour.
[14 May 2010 16:34]
L R
How do you solve the problem that the cursor is declared inside an if statement? If you declare the cursor at the begining of SP you can´t set different things into it... I have the same problem migrating from SQL Server to MySQL and I don't know how to solve this.. Can you help me? Sorry for my english :(