这是我的程序

  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是strinh“ mmmm,ssss,eeee”

请任何人帮助我。
提前致谢。

最佳答案

您必须对concat之类的局部变量使用set@variable

set @query = concat("INSERT INTO accesstmp (`accesscode`) VALUES ('",accescodeString,"')");


-- ...

set @query1 = "SELECT ...

09-26 22:47
查看更多