This is a discussion on newbie: What is wrong in this SP? within the MySQL Database forums, part of the Database Forums category; Hey I'm new to MySql5 and I'm trying to write my first stored procedure. Below is a stored ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hey
I'm new to MySql5 and I'm trying to write my first stored procedure. Below is a stored procedure I'm trying to add to the database, but it gives errors (the 2 errors are listed below too)... I'm stucked here. CREATE PROCEDURE SaveProperty() BEGIN DECLARE @var1 INT; END; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@var1 INT' at line 3 mysql> END; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1 Any suggestions to what I'm doing wrong are welcome! Jeff |
|
|||
|
"Jeff" <it_consultant1@hotmail.com.NOSPAM> wrote:
> > CREATE PROCEDURE SaveProperty() > BEGIN > DECLARE @var1 INT; > END; > > ERROR 1064 (42000): You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right > syntax to use near '@var1 INT' at line 3 > Any suggestions to what I'm doing wrong are welcome! You're trying to declare a user variable. User variables have names starting with @ and must not be declared. The scope of a user variable is the connection, the scope of a local variable is the surrounding BEGIN ... END block. Local variable names must not start with @. Try this: CREATE PROCEDURE SaveProperty() BEGIN DECLARE var1 INT; END; XL -- Axel Schwenke, Support Engineer, MySQL AB Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/ MySQL User Forums: http://forums.mysql.com/ |
|
|||
|
thanks
"Axel Schwenke" <axel.schwenke@gmx.de> wrote in message news:99u0pe.d77.ln@xl.homelinux.org... > "Jeff" <it_consultant1@hotmail.com.NOSPAM> wrote: >> >> CREATE PROCEDURE SaveProperty() >> BEGIN >> DECLARE @var1 INT; >> END; >> >> ERROR 1064 (42000): You have an error in your SQL syntax; check the >> manual that corresponds to your MySQL server version for the right >> syntax to use near '@var1 INT' at line 3 > >> Any suggestions to what I'm doing wrong are welcome! > > You're trying to declare a user variable. User variables have names > starting with @ and must not be declared. The scope of a user variable > is the connection, the scope of a local variable is the surrounding > BEGIN ... END block. Local variable names must not start with @. > Try this: > > CREATE PROCEDURE SaveProperty() > BEGIN > DECLARE var1 INT; > END; > > > XL > -- > Axel Schwenke, Support Engineer, MySQL AB > > Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/ > MySQL User Forums: http://forums.mysql.com/ |