0
我正在嘗試編寫一個MySQL存儲過程,該過程將(1)將值插入到Employee表中並(2)接收新員工的部門編號,掃描部門工作的任何項目的Project表on和(3)將這些項目與僱員的SSN一起插入到Works_On表中。MySQL存儲過程與光標錯誤
我正試圖用遊標來做到這一點,但仍然遇到我無法弄清楚的語法錯誤。當前的錯誤是在我聲明遊標的地方,但我不知道如何解決它。我已經嘗試了很多東西,希望有人能夠看到這個錯誤。
Use Company
DELIMITER //
Create Procedure SP_Insert_NewEmployee
(
IN fname varchar(30),
IN minit char(1),
IN lname varchar(30),
IN ssn char(9),
IN bdate date,
IN address varchar(50),
IN sex char(1),
IN salary decimal(10,1),
IN super_ssn char(9),
IN dno int
)
Begin
Declare projectNumber Integer;
Declare myCursor2 = CURSOR FOR
SELECT Pnumber
FROM PROJECT
Where Dnum = @dno;
#Insert into Employee
Insert into EMPLOYEE
(
Fname,
Minit ,
Lname ,
Ssn ,
Bdate ,
Address ,
Sex,
Salary ,
Super_ssn,
Dno
)
Values
(
$fname ,
$minit ,
$lname,
$ssn ,
$bdate ,
$address ,
$sex ,
$salary ,
$super_ssn ,
$dno
);
END
#Find projects by new employee's dept
OPEN myCursor2;
FETCH NEXT
FROM myCursor2
INTO
projectNumber
WHILE @@FETCH_STATUS = 0
BEGIN
Insert Into WORKS_ON
Values
(
ssn,
projectNumber,
0
)
FETCH NEXT
FROM myCursor2
INTO
projectNumber
END
CLOSE myCursor2;
DEALLOCATE myCursor2;
END
END
//
DELIMITER ;
錯誤代碼是1064 .....在遊標附近 – cisstudent123
更好的是添加註釋而不是回答,首先你必須聲明遊標爲'DECLARE cur_saving_acc CURSOR FOR',代碼搞砸了,所以不知道其他問題不存在 – Susang
這是第一個問題....我混合了MySQL和SQL Server遊標語法。謝謝! – cisstudent123