在存储过程之外使用if语句 [英] Using an if statement outside a stored procedure

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

问题描述

我正在尝试执行此代码

set @id = 0;
set @the_number = 0;
set @the_message = 0;
set @selected_message = 0;

SELECT id, dest_msisdn, text_message INTO @id, @the_number, @the_message FROM incoming_sms where service_id = 6015592000101762 AND job_status = 0 limit 1;

if(@the_message LIKE '%Bank%')then

select 'h';

end if;

但是我不断收到错误消息

but i keep getting an error on

if(@the_message LIKE '%Bank%')then

select 'h'' at line 1 

为什么我会产生错误?

推荐答案

您需要将代码放入受约束的过程或函数中,才能使用IF语句 https://bugs.mysql.com/bug.php?id = 48777

You need to put your code inside of a strored procedure or function to use the IF statement https://stackoverflow.com/a/12954385/5308054. Here you can see a feature request to fix it https://bugs.mysql.com/bug.php?id=48777

可以不使用IF语句重写查询,但是我认为这个问题也无法以这种方式回答.

It is possible to rewrite query without IF statements but I think this question is too to be answered in such way.

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

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