1 votes

error en stored procedure: is not valid at this position, expecting an identifier

I am new to MySQL and I am trying to make a stored procedure to do a login in vb.net.

But when I want to create it, I get the error message

"@u" is not valid at this position, expecting an identifier

The Stores is

CREATE PROCEDURE `sp_login` (@u varchar(50), @p varchar(100))
As
DECLARE @ap varchar(50)
BEGIN
SELECT @ap=passwd FROM transportesclaudia.usuarios WHERE login=@u

IF @ap IS NULL
RETURN -1
ELSE
IF @ap=@p
RETURN 1
ELSE
RETURN -2

END

1voto

Aprendiz Points 1310
  • First, it seems to me that you are mixing up syntax, since [if you check the SQL Server doc] you will see that it does use the prefix @ for the declaration of variable names; while on the other hand MySQL does not require it.
  • The syntax of a conditional in MySQL is: IF THEN ELSEIF THEN END IF
  • It seems to me that MySQL cannot do return of a value within an AP, so instead try with a SELECT so that when you invoke it

Then test your PA in this way:

DELIMITER //
CREATE PROCEDURE `sp_login` (u varchar(50), p varchar(100))
    BEGIN
        DECLARE ap varchar(50);
        SELECT ap=passwd FROM transportesclaudia.usuarios WHERE login=u;

        IF ap IS NULL THEN
            SELECT -1;
        ELSEIF ap=p THEN
            SELECT 1;
        ELSE
            SELECT -2;
        END IF;
    END;
//

0 votes

Ohhh very good, it's good that you clarified it for me, only that it sends me the DELIMITER error, it says that it waits for CREATE, I copied your code to see if I was wrong but no.... :/

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X