Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a procedure in mySql with parameters

I am trying to make a stored procedure using mySQL. This procedure will validate a username and a password. I'm currently running mySQL 5.0.32 so it should be possible to create procedures.

Heres the code I've used. All I get is an SQL syntax error.

   GO     CREATE PROCEDURE checkUser     (IN @brugernavn varchar(64)),IN @password varchar(64))     BEGIN     SELECT COUNT(*)  FROM bruger WHERE bruger.brugernavn=@brugernavn AND bruger.pass=@Password;     END; 

Thank you in advance

like image 872
Peter Rasmussen Avatar asked Feb 18 '11 08:02

Peter Rasmussen


People also ask

Can you pass parameters to the procedure?

To pass one or more arguments to a procedure In the calling statement, follow the procedure name with parentheses. Inside the parentheses, put an argument list. Include an argument for each required parameter the procedure defines, and separate the arguments with commas.

Can a stored procedure use parameters?

Parameters are used to exchange data between stored procedures and functions and the application or tool that called the stored procedure or function: Input parameters allow the caller to pass a data value to the stored procedure or function.


2 Answers

I figured it out now. Here's the correct answer

CREATE PROCEDURE checkUser  (    brugernavn1 varchar(64),    password varchar(64) )  BEGIN     SELECT COUNT(*) FROM bruger     WHERE bruger.brugernavn=brugernavn1     AND bruger.pass=password;  END;  

@ points to a global var in mysql. The above syntax is correct.

like image 105
Peter Rasmussen Avatar answered Nov 08 '22 22:11

Peter Rasmussen


(IN @brugernavn varchar(64)**)**,IN @password varchar(64)) 

The problem is the )

like image 35
Alexo Avatar answered Nov 08 '22 21:11

Alexo