我在try 创建这stored procedure时遇到了一些困难,欢迎任何形式的帮助:

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分:

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;

Database相关问答推荐

如果我想支持我的工作负载,我需要多少个 node ?

数据库是序列图中的控制器还是边界?

如何在 Angular 中使用 IndexedDB?

用于存储人与聊天消息的数据库设计

sql-dump 有什么用?

mysql搜索表名的段

如何在 SQL Server 中生成随机数据?

MS SQL 中查询的优先级

如何使用 MySQL Workbench 更改字段的值?

Android Room:如何建模关系?

SQLite同时读写

Django 数据库值的最佳推荐方式是什么?

Redis-cli - Select 哪个实例?

什么是数据库中的死锁?

对于 N:M 关系,在 MongoDB 中推荐的级联删除等效项是什么?

用于存储文件夹系统的数据库模式的 Select

设计数据库来保存不同的元数据信息

最小覆盖和功能依赖

带数据库的Electron 应用程序

自引用表上的 SQL 递归查询 (Oracle)