日期:2014-05-16  浏览次数:20794 次

mysql中if esle 问题
在sqlserver 中的语句:
if (not exists (select null from tb where ExpLevel=0)) 
select 0 as Experience
else 
select Experience from tb where ExpLevel=0
在mysql中要怎么写呢??
求帮助!

------解决方案--------------------
DELIMITER $$
CREATE PROCEDURE ff()
BEGIN
IF (NOT EXISTS (SELECT NULL FROM tb WHERE ExpLevel=0)) THEN
SELECT 0 AS Experience;
ELSE
SELECT Experience FROM tb WHERE ExpLevel=0;
END IF;
END$$
DELIMITER ;
------解决方案--------------------
不能,MYSQL不支持匿名块
------解决方案--------------------
MySQL流程控制实例,详细介绍:

http://blog.csdn.net/business122/article/details/7565653