mysql语法不好用呀,if判断都过不了

fddddddddddd 2012-12-25 10:10:33
需要完成的简单功能:

C语法:
if(true)
printf("为真");
else
printf("为假");

mysql语法:
if true then
select '为真';
else
select '为假';
end if
但是错的,谁知道呀?
...全文
203 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
欢乐的尼美 2012-12-25
  • 打赏
  • 举报
回复
mysql > DELIMITER // mysql > CREATE PROCEDURE proc2(IN parameter int) -> begin -> declare var int; -> set var=parameter+1; -> if var=0 then -> insert into t values(17); -> end if; -> if parameter=0 then -> update t set s1=s1+1; -> else -> update t set s1=s1+2; -> end if; -> end; -> // mysql > DELIMITER ;
ACMAIN_CHM 2012-12-25
  • 打赏
  • 举报
回复
MYSQL支持IF THEN, 但这种非SQL语句,过程语句只能写在MYSQL的存储过程中。 毕竟MYSQL与SQL SERVER是不一样的。
rucypli 2012-12-25
  • 打赏
  • 举报
回复
这种语句只能在存储过程或者函数里面使用 不能像sqlserver一样单独执行
WWWWA 2012-12-25
  • 打赏
  • 举报
回复
是在SP中?MYSQL不支持匿名块 delimiter $$ create procedure dd() begin if true then ... else ... end if; end$$ delimiter ;
fddddddddddd 2012-12-25
  • 打赏
  • 举报
回复
if true then select '为真'; else select '为假'; end if -------------------- [SQL] if true then select '为真'; [Err] 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 true then select '为真'' at line 1
WWWWA 2012-12-25
  • 打赏
  • 举报
回复
你的代码贴出来,提示什么

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧