2013-12-12 62 views
0
 
ERROR 1064 (42000): 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 '= (se 
lect ifnull(max(manufactureId+1),1) from tbl_Manufacturer 
       ) ; 
create procedure ManufactureAdd(
    p_manufactureName longtext, 
    p_address longtext, 
    p_phone varchar(50), 
    p_email varchar(50), 
    p_description longtext 
) 
begin 
    declare p_manufactureId = (select ifnull(max(manufactureId+1),1) from tbl_Manufacturer 
    ) ; 

    insert into tbl_Manufacturer(
     manufactureId, 
manufactureName, 
address, 
phone, 
email, 
description 
) 
VALUES  
( 
p_manufactureId, 
p_manufactureName, 
p_address, 
p_phone, 
p_email, 
p_description 
) ; 

SELECT p_manufactureId ; 

end 
+0

的代碼在你的錯誤指消息不會顯示在您發佈的代碼中。 – 2013-12-12 08:31:27

+0

現在檢查@MikeW – Nisar

回答

2

嘗試使用SELECT..INTO條款和簡單的用戶變量 -

CREATE PROCEDURE ManufactureAdd(
    p_manufactureName longtext, 
    p_address longtext, 
    p_phone varchar(50), 
    p_email varchar(50), 
    p_description longtext) 
BEGIN 
    SELECT IFNULL(MAX(manufactureId + 1), 1) INTO @p_manufactureId FROM tbl_Manufacturer; 

    INSERT INTO tbl_Manufacturer (manufactureId, manufactureName, address, phone, email, DESCRIPTION) 
    VALUES (@p_manufactureId, p_manufactureName, p_address, p_phone, p_email, p_description); 

    SELECT @p_manufactureId; 
END 
0

試試這個:

CREATE PROCEDURE ManufactureAdd(
    p_manufactureName LONGTEXT, 
    p_address LONGTEXT, 
    p_phone VARCHAR(50), 
    p_email VARCHAR(50), 
    p_description LONGTEXT 
) 
BEGIN 
    DECLARE p_manufactureId INT; 
    SELECT IFNULL(MAX(manufactureId+1),1) INTO p_manufactureId FROM tbl_Manufacturer; 

    INSERT INTO tbl_Manufacturer(
     manufactureId, manufactureName, address, phone, email, description 
    ) 
    VALUES ( 
     p_manufactureId, p_manufactureName, p_address, p_phone, p_email, p_description 
    ); 

    SELECT p_manufactureId ; 
END