Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
newbie: What is wrong in this SP?
Old
  (#1)
Jeff
Guest
 
Posts: n/a
Default newbie: What is wrong in this SP? - 06-04-2007, 07:50 AM

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


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: newbie: What is wrong in this SP?
Old
  (#2)
Axel Schwenke
Guest
 
Posts: n/a
Default Re: newbie: What is wrong in this SP? - 06-04-2007, 07:50 AM

"Jeff" <EMAIL REMOVED> 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/
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: newbie: What is wrong in this SP?
Old
  (#3)
Jeff
Guest
 
Posts: n/a
Default Re: newbie: What is wrong in this SP? - 06-04-2007, 07:50 AM

thanks


"Axel Schwenke" <EMAIL REMOVED> wrote in message
news:EMAIL REMOVED...
> "Jeff" <EMAIL REMOVED> 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/



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top