MySQL在存储过程中引发错误IF函数

时间:2013-07-12 10:33:51

标签: mysql stored-procedures mysql-error-1064

我有一些关于我的mysql存储过程的问题,mysql总是显示错误1064,错误mysql语法。哪里我错了?

   DELIMITER $$

   USE `itin`$$

   DROP PROCEDURE IF EXISTS `sp_Transaction`$$

   CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_Transaction`(IN inpt TINYINT(4), IN inpt2 TINYINT(4))
   BEGIN

   IF((inpt = 0) AND (inpt2 = 0)) THEN  
   SELECT idtr_inventory, showStatus(idms_status) AS idms_status, showLocation(idms_location) AS idms_location
, showUnitType(idms_unittype) AS idms_unittype, USER, user_email
, showDepartment(idms_department) AS idms_department, asset_tag, sn, brand, model, showBBUser(bb_user) AS bbUser
, dt_purchase, warranty, dt_warranty_exp, nm_computer, ip_address, remarks
   FROM tr_inventory;

 ELSE IF(inpt = 0) THEN
 SELECT idtr_inventory, showStatus(idms_status) AS idms_status, showLocation(idms_location) AS idms_location
, showUnitType(idms_unittype) AS idms_unittype, USER, user_email
, showDepartment(idms_department) AS idms_department, asset_tag, sn, brand, model, showBBUser(bb_user) AS bbUser
, dt_purchase, warranty, dt_warranty_exp, nm_computer, ip_address, remarks
 FROM tr_inventory WHERE (idms_location = inpt2);

ELSE IF(inpt2 = 0) THEN
SELECT idtr_inventory, showStatus(idms_status) AS idms_status, showLocation(idms_location) AS idms_location
, showUnitType(idms_unittype) AS idms_unittype, USER, user_email
, showDepartment(idms_department) AS idms_department, asset_tag, sn, brand, model, showBBUser(bb_user) AS bbUser
, dt_purchase, warranty, dt_warranty_exp, nm_computer, ip_address, remarks
FROM tr_inventory WHERE (idms_unittype = inpt)

ELSE 
SELECT idtr_inventory, showStatus(idms_status) AS idms_status, showLocation(idms_location) AS idms_location
, showUnitType(idms_unittype) AS idms_unittype, USER, user_email
, showDepartment(idms_department) AS idms_department, asset_tag, sn, brand, model, showBBUser(bb_user) AS bbUser
, dt_purchase, warranty, dt_warranty_exp, nm_computer, ip_address, remarks
FROM tr_inventory WHERE (idms_unittype = inpt) AND (idms_location = inpt2);

END IF;
END IF;
END IF;

END$$

DELIMITER ;

如果声明到底是错的吗?如果是的话,我需要放在哪里?感谢。

错误: 查询:CREATE DEFINER = root @ localhost程序sp_Transaction(inpt tinyint(4),IN inpt2 TINYINT(4))if if((inpt = 0)AND ... 错误代码:1064 您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在'else

附近使用正确的语法

1 个答案:

答案 0 :(得分:1)

您错过了;

...
FROM tr_inventory WHERE (idms_unittype = inpt);
                                              ^------here
ELSE 
...