【问题标题】:Multiple condition in if....else inside stored procedureif....else 中的多个条件在存储过程中
【发布时间】:2016-04-01 17:24:44
【问题描述】:
IF region='Mumbai' OR region='Chennai' OR region='Bangalore' OR region='Pune' region='Coimbatore' OR region='Ahmedabad' THEN
            SET region='South-west';
        ELSE
            SET region='North+East';
        END IF;

我正在尝试创建一个 sp 我在上述条件中有错误。当我删除上述 if 条件时,存储过程的其余部分工作正常。

我在 if 语句中收到多个或条件的错误。

请帮忙。

【问题讨论】:

    标签: mysql if-statement stored-procedures


    【解决方案1】:

    您缺少OR。试试:

    IF region='Mumbai' OR region='Chennai' OR region='Bangalore' OR region='Pune'  OR region='Coimbatore' OR region='Ahmedabad' THEN
    

    另外,我认为IN 也可以在这里工作(我不能 100% 确定,因为我不经常使用 MySQL):

    IF region IN ('Mumbai','Chennai','Bangalore','Pune','Coimbatore','Ahmedabad') THEN
    

    如果 MySQL 对它满意,那将更具可读性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多