我在尝试执行以下操作时收到错误#1064,帮助我解决它

时间:2014-02-21 07:28:03

标签: mysql

我需要检查布尔变量dynamic_select,如果它是1,那么我必须从设备表中插入相应的设备

CREATE DEFINER=`root`@`localhost` PROCEDURE
 `sp_CONTRACT_EQUIPMENTS( P_CONTRACT_EQUIPMENT_ID INT,
                          P_CONTRACT_ID INT,
                          P_CATEGORY_ID INT,
                          P_DYNAMIC_SELECT TINYINT )`
BEGIN
  DECLARE V_DYNAMIC_SELECT TINYINT;
  DECLARE V_EQUIPMENT_ID INT;
  SELECT DYNAMIC_SELECT INTO V_DYNAMIC_SELECT FROM CONTRACT_EQUIPMENTS
  WHERE CONTRACT_ID=P_CONTRACT_ID;
  SELECT EQUIPMENT_ID INTO V_EQUIPMENT_ID FROM EQUIPMENT E
    INNER JOIN CONTRACT_CATEGORY CC
      ON E.CONTRACT_ID = CC.CONTRACT_ID
  WHERE CC.CATEGORY_ID = P_CATEGORY_ID;
  IF V_DYNAMIC_SELECT=1 THEN
    IF NOT EXISTS 
      (SELECT EQUIPMENT_ID FROM CONTRACT_EQUIPMENTS CE1 
       WHERE CE1.EQUIPMENT_ID=E.EQUIPMENT_ID AND 
         CE1.CONTRACT_ID=P_CONTRACT_ID) THEN 
      INSERT 
        INTO `CONTRACT_EQUIPMENTS`(CONTRACT_EQUIPMENT_ID,CONTRACT_ID,EQUIPMENT_ID,DYNAMIC_SELECT)
        VALUES(P_CONTRACT_EQUIPMENT_ID,P_CONTRACT_ID,V_EQUIPMENT_ID,0);
    END IF;
  END IF; 
END

1 个答案:

答案 0 :(得分:0)

不需要在程序名称周围返回刻度线(`)。

这是错误的:

`sp_CONTRACT_EQUIPMENTS(P_CONTRACT_EQUIPMENT_ID INT,
P_CONTRACT_ID INT,P_CATEGORY_ID INT,P_DYNAMIC_SELECT TINYINT)`

更改为:

sp_CONTRACT_EQUIPMENTS( P_CONTRACT_EQUIPMENT_ID INT,
P_CONTRACT_ID INT, P_CATEGORY_ID INT, P_DYNAMIC_SELECT TINYINT )