CREATE PROCEDURE `checkAdminAccess`
(
IN accountID INT
)
BEGIN
DECLARE staffID INT;
#DECLARE num INT;
SELECT StaffID INTO staffID
FROM staff
WHERE AccountID = accountID
AND IsAdmin = 1;
SELECT staffID;
IF (staffID IS NULL) THEN
CALL raise(1356, 'Admin access required.');
END IF;
END;
對於任何輸入,我都將staffID設置爲NULL。 例如:Mysql變量值爲空
call checkAdminAccess(3); #returns null
call checkAdminAccess(6); #returns null
而且我下面的數據是:
INSERT INTO `staff` (`StaffID`,`AccountID`,`RoleID`,`ManagerID`,`IsAdmin`) VALUES (1,3,1,1,0);
INSERT INTO `staff` (`StaffID`,`AccountID`,`RoleID`,`ManagerID`,`IsAdmin`) VALUES (2,6,2,1,1);
誰能告訴我怎麼做選擇一個值到MySQL中的變量?
[MySQL Select into variable]可能的重複(http://stackoverflow.com/questions/13351479/mysql-select-into-variable) – Barett