MySQL存储过程中的if语句,用于选择数据 [英] If-statement in the MySQL stored procedure for selecting data

查看:114
本文介绍了MySQL存储过程中的if语句,用于选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个SQL代码:

I have the next SQL code:

DELIMITER $$

CREATE PROCEDURE `test`.`new_procedure` (queryString VARCHAR(255))
BEGIN
    SELECT @tempValue = COUNT(*) FROM test.userdata_extended WHERE inn LIKE queryString;
    IF @tempValue > 0 SELECT * FROM test.userdata_extended WHERE inn LIKE queryString;
END $$

我将COUNT*结果放入@tempValue变量中. 然后,我尝试比较它是否大于零.

I'm putting the COUNT* result into @tempValue variable. Then I'm trying to compare it for being greater than zero.

我在语句比较过程中遇到了错误. MySQL向我报告一个UNEXPECTED SELECT SYM错误.是什么意思?

I'm getting error with the statement comparing process. MySQL reports me a UNEXPECTED SELECT SYM error. What does it mean?

这也将是对另一个表的检查.我需要IF-ELSE语句,因为基于所有查询结果,我的过程必须返回准确的代码错误值(可能有所不同),以便我开发的应用程序处理或提供数据(如果一切正常).

Also this would be a check for another tables. I need IF-ELSE statements, because basing on several query result my procedure must return the exact code error value (which could be different) for the my developed application to handle or giving the data, if all is fine.

如何解决此问题?

谢谢

推荐答案

您已经在if语句中忘记了THEN.您需要添加THEN.

You have forgot the THEN in your if statement. You need to add the THEN.

赞:

IF @tempValue > 0 THEN ...your statement 
END IF;

您还忘记了添加END IF;还要添加它.

You have also forgot to add the END IF; add this also.

参考站点在此处.

这篇关于MySQL存储过程中的if语句,用于选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆