0
エラー 1064 (42000): SQL 構文にエラーがあります。そのマニュアルを確認してください
near '= (se
tbl_Manufacturer から ifnull(max(manufactureId+1),1) を選択
                ) ;
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
4

2 に答える 2

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
于 2013-12-12T08:35:08.680 に答える
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
于 2013-12-12T08:48:21.187 に答える