【发布时间】:2018-12-26 15:32:45
【问题描述】:
在我安装的 phpmyadmin 中,SQL 选项卡不处理 IF THEN 语句。但是,它确实可以正确处理 IF() 函数。例如,这很好用:
SET @thisyear = IF(YEAR(CURRENT_DATE) = 2018, 2018, 2019);
SELECT @thisyear AS ThisYear, `foobar`.`id` AS ID ...
但是,以下会产生错误:
IF year(CURRENT_DATE) = '2018' THEN
SET @thisyear = '2018';
END IF;
SELECT @thisyear AS ThisYear, `foobar`.`id` AS ID ...
这是错误信息:
#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 year(CURRENT_DATE) = '2018' THEN
SET @thisyear = '2018'' at line 1
我的 phpmyadmin 配置有问题,还是我需要在使用 IF 语句之前先调用一些东西?提前致谢。
【问题讨论】:
-
你只能在存储的程序(过程、函数、触发器、事件)中使用 if..then..end if..then..end
标签: mysql sql phpmyadmin