mySQL If语句 [英] mySQL If statement

查看:78
本文介绍了mySQL If语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使这个If Statement工作,但我似乎无法让它做我想要的。如果我选择@result,它会给我值0,那么为什么IF语句不起作用?

I am trying to make this If Statement work, but I can't seem to make it do what I want. If I do a select @result, It'll give me the value 0, then why doesn't the IF statement work?

SET @message = '((sometihng here))';
select LEFT(@message, 1) into @firstChar;
select STRCMP(@firstChar,'(') into @result;
IF (@result = 0) THEN  
SET @message = 'true';
//more selects and cals here;
END IF;
select @message;

我应该得到了,但我没有告诉我一个错误:

I should get true, but I don't it shows me an error:


SQL查询:IF(@result = 0)然后设置@message ='true';

MySQL说:


1064 - 您的SQL语法有错误;请查看
对应于您的MySQL服务器版本的手册,以获得使用$ b $的正确语法b在'IF(@result = 0)THEN SET @message ='true''第1行附近

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF (@result = 0) THEN SET @message = 'true'' at line 1


推荐答案

尝试使用函数 http:/ /dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if

SELECT IF(@result = 0, 'true', '((something here))') AS message

这篇关于mySQL If语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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