sql语句检查错误

SET @tongji_hour = '2012-8-14 0:00:00';
IF DATE_FORMAT(@tongji_hour,'%Y-%m-%d %H:00:00')=DATE_FORMAT(@tongji_hour,'%Y-%m-%d 00:00:00') THEN
      SELECT @tongji_hour;
END IF;

报错:[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 DATE_FORMAT(@tongji_hour,'%Y-%m-%d %H:00:00')=DATE_FORMAT(@tongji_hour,'%Y-%m' at line 1

判断是不是整点
阅读 3.6k
1 个回答

DROP PROCEDURE IF EXISTS testx;
DELIMITER //
CREATE PROCEDURE testx ()
BEGIN
SET @tongji_hour = '2012-8-14 0:00:00';
IF DATE_FORMAT(@tongji_hour,'%Y-%m-%d %H:00:00')=DATE_FORMAT(@tongji_hour,'%Y-%m-%d 00:00:00') THEN

  SELECT @tongji_hour;

END IF;
END;
//
DELIMITER ;

call testx ();

推荐问题