0
這是我的程序MySQL的過程不是excecuting
DELIMITER //
CREATE PROCEDURE GET_CHECK_COURSES(IN distid int, IN `accescodeString` TEXT)
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS accesstmp (
`Id` INT NOT NULL AUTO_INCREMENT,
`accesscode` VARCHAR(100) NOT NULL,
PRIMARY KEY (`Id`)) ENGINE=InnoDB;
@query = "INSERT INTO accesstmp (`accesscode`) VALUES ('",accescodeString,"')";
PREPARE stmt1 FROM @query;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
@query1 = "SELECT
cde.code_status,
co.course_code,
co.course_name,
u.organization,
u1.email as licencinguser,
cul.status,
cul.learning_completion_date
FROM cdp_access_codes as cde
LEFT JOIN cdp_course as co ON cde.course_id = co.course_id
LEFT JOIN cdp_user as u ON u.user_id = cde.licensing_user_id
LEFT JOIN cdp_user as u1 ON u1.user_id = cde.user_id
LEFT JOIN cdp_accesscode_courses as cac ON cac.code_id = cde.code_id
LEFT JOIN cdp_user_licenses as cul ON cul.user_license_id = cac.course_subscription_id
JOIN accesstmp as act ON act.accesscode = cde.access_code
WHERE
cde.distributor_user_id = $distributorId
GROUP BY cde.access_code";
PREPARE stmt2 FROM @query1;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;
END //
DELIMITER ;
但是,當我執行此我得到一個語法錯誤
#1064 - 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 '@query = "INSERT INTO accesstmp (`accesscode`) VALUES ('",accescodeString,"')"; ' at line 10
我parametrs都是這樣的參數值的方式distid = 24和accescodeString是嚴格「mmmm,ssss,eeee」
請任何人幫助我。 在此先感謝。
我不認爲有必要使用13.5準備的SQL語句語法](https://dev.mysql.com/ doc/refman/5.7/en/sql-syntax-prepared-statements.html)在'INSERT'中。 '$ distributorId'變量應該是一個輸入參數。使用[13.7.4 SET語法](https://dev.mysql.com/doc/refman/5.7/en/set-statement.html)分配[9.4用戶定義的變量](https:// dev。 mysql.com/doc/refman/5.7/en/user-variables.html)('\'@query \'')。使用['CONCAT()'](https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat)函數進行連接。 – wchiquito