Wells
Wells

Reputation: 10969

MySQL stored procedure: variable in WHERE clause?

Can you not do the following w/ MySQL stored procedures?/

DROP PROCEDURE IF EXISTS `test`;
DELIMITER //

CREATE PROCEDURE TEST (team varchar(30))
BEGIN
    SELECT * FROM TEAMS WHERE TEAM_ID = @team;
END
//

Where @team (or team) is the variable passed to the stored procedure?

Upvotes: 2

Views: 7142

Answers (1)

OMG Ponies
OMG Ponies

Reputation: 332661

You need to use:

DROP PROCEDURE IF EXISTS `test`;
DELIMITER //

CREATE PROCEDURE TEST (IN_TEAM_ID varchar(30))
BEGIN

    SELECT t.* 
      FROM TEAMS t
     WHERE t.team_id = IN_TEAM_ID;

END //

DELIMITER ;

There's no @ notation when referencing stored procedure parameters.

Upvotes: 8

Related Questions