本文介绍了使用“if”和“else”存储过程MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,伙计们怎么了?我在尝试创建此存储过程时遇到一些困难,欢迎任何类型的帮助:

Hey guys what's up?? I'm havig some difficulties when trying to create this stored procedure, any kind of help is welcome:

create procedure checando(in nombrecillo varchar(30), in contrilla varchar(30), out resultado int)

begin

if exists (select * from compas where nombre = nombrecillo and contrasenia = contrilla) then
    set resultado = 0;
else if exists (select * from compas where nombre = nombrecillo) then
    set resultado = -1;
else
    set resultado = -2;
end if;
end;

我正在处理的表格是:

+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| Nombre      | varchar(30) | YES  |     | NULL    |       |
| contrasenia | varchar(30) | YES  |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+

非常感谢您的时间

推荐答案

问题是你没有关闭 if 您需要一个 elseif

The problem is you either haven't closed your if or you need an elseif:

create procedure checando(
    in nombrecillo varchar(30),
    in contrilla varchar(30),
    out resultado int)
begin

    if exists (select * from compas where nombre = nombrecillo and contrasenia = contrilla) then
        set resultado = 0;
    elseif exists (select * from compas where nombre = nombrecillo) then
        set resultado = -1;
    else
        set resultado = -2;
    end if;
end;

这篇关于使用“if”和“else”存储过程MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 11:20