Syntax error with case in mysql using SP

0

Well from phpMyAdmin I'm doing a crud with case, and well he tells me that there is syntax error nothing else I do not see something bad.

My code is this:

create PROCEDURE usuarioXY
(in _idUser int(11),
in _usuario char(50),
in _consetrasena char(50),
in accion varchar(40)
)
begin 
    case accion
     when 'nuevo' then 
        insert into usuarios (usuario, contrasena) values (_usuario, _contrasena);
     when 'editar' then 
        update usuarios set 
        usuario = _usuario, contrasena = _contrasena;
     when 'eliminar' then 
        delete from usuarios where idUser = _idUser;
     when 'consulta' then 
        select * from usuarios where idUser = _idUser;
     end case 
end

The error that comes to me is this:

  

1064 - Something is wrong in its syntax near '' on line 10

which is after the case, is in the line of the insert:

when 'nuevo' then 
    insert into usuarios (usuario, contrasena) values (_usuario, _contrasena);

Can someone tell me what may be happening? I can not see the error.

    
asked by Lalo Alexander 20.09.2017 в 21:26
source

1 answer

1

The CASE instruction does not control the instruction execution flow, for this you have the conditional instruction IF: IF Syntax

Personally, I do not see any advantage to "multi-use" procedures, "hinder" readability, maintenance and above all are not predictable to sustain an execution plan. You can opt for UPSERT functions, for example: INSERT ... ON DUPLICATE KEY UPDATE Syntax

    
answered by 20.09.2017 в 21:59