gpt4 book ai didi

mysql - mySql传递多个参数时CALL语句语法错误

转载 作者:行者123 更新时间:2023-11-29 08:28:53 24 4
gpt4 key购买 nike

我正在 MySQL 5.6.11 中运行查询。我创建了以下存储过程

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `digital_audio_test_detail`(IN temp VARCHAR(50), IN temp2 VARCHAR(50))
BEGIN
SET @temp_query = CONCAT('SELECT * FROM ',temp);
SET @final_query = CONCAT(@temp_query,'WHERE', temp,'.unit_test_result_id =',temp2);
PREPARE stmt FROM @final_query;
EXECUTE stmt;
END

当我在查询页面中调用此过程时,我在其 CALL 处收到语法错误。这就是我执行查询的方式。

SELECT unit_test_result.*, @temp1 := unit_test.name, @temp2 := unit_test_result.id 
FROM unit_test_result, unit_test
WHERE unit_test_result.test_run_id = 2
AND unit_test.id = unit_test_result.unit_test_id;
CALL digital_audio_test_detail(@temp1, @temp2);

我必须将两个参数传递给该过程。当我创建一个仅包含第一个参数的过程并调用它一个参数时,它执行得很好。但是当我使用两个参数时,我收到语法错误。需要帮忙。谢谢

最佳答案

SET @final_query = CONCAT(@temp_query,'WHERE', temp,'.unit_test_result_id =',temp2);

您正在构建的字符串不是有效的查询。

在 WHERE 前后添加空格,如

SET @final_query = CONCAT(@temp_query,' WHERE ', temp,'.unit_test_result_id =',temp2);

关于mysql - mySql传递多个参数时CALL语句语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17198982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com