2015-05-14 53 views
0

我知道微軟的SQL服務器,我認爲這段代碼不包含錯誤。但Mysql thow一個exent,我不能undendant。是任何人都可以解釋這對我和 請,給我的MySQL函數,視圖,存儲過程實例的網站名稱如何在mysql工作臺中創建存儲過程?

CREATE PROCEDURE spInsertEmployee 
(
Employee_Name nvarchar(20), 
Employee_Surname nvarchar(20), 
Department_Name nvarchar(20) 
) 
BEGIN 
declare Department_Id int; /*error*/ 
select Id into Department_Id from tblDepartment where  tblDepartment.Department_Name=Department_Name; 
insert into tblVeri(Employee_Name,Employee_Surname,Department_Id)  values(Employee_Name,Employee_Surname,Department_Id); 
END /*error*/ 
+0

您需要在開始處提供一個分隔符,並以'end;'結尾;' –

+0

ok。這是工作。謝謝 – stackoverflowmet

回答

0

必須爲參數定義IN

DELIMITER $$ 

CREATE PROCEDURE spInsertEmployee 
(
IN Employee_Name nvarchar(20), 
IN Employee_Surname nvarchar(20), 
IN Department_Name nvarchar(20) 
) 
BEGIN 
declare Department_Id INT; 

select Id into Department_Id from tblDepartment WHERE tblDepartment.Department_Name=Department_Name; 
insert into tblVeri(Employee_Name,Employee_Surname,Department_Id)  VALUES(Employee_Name,Employee_Surname,Department_Id); 

END;