这是我的程序
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
我的参数就像这个参数值distid = 24而且accescodeString是一个strmmh“mmmm,ssss,eeee”
请任何人帮助我。 提前谢谢。
答案 0 :(得分:1)
您必须将concat
和set
用于@variable
等本地变量:
set @query = concat("INSERT INTO accesstmp (`accesscode`) VALUES ('",accescodeString,"')");
-- ...
set @query1 = "SELECT ...