要求我编写一个存储过程,该过程将创建(插入)调查响应,以SurveyGUID为输入,而SurveyResponseGUID为输出。但是,当我插入响应后设置输出时,我返回null。
执行插入时,是否可以设置OUT参数?
插入有效,当我删除INTO零件时,设置输出参数的查询也可以独立工作。我试图找到解决方案,但我并不幸运。我是MySQL的新手,所以将不胜感激任何帮助或技巧。
USE db;
DROP PROCEDURE IF EXISTS spCreateSurveyResponse;
DELIMITER ??
CREATE PROCEDURE spCreateSurveyResponse(
IN surveyGUID varchar(36),
OUT responseGUID varchar(36))
BEGIN
SET @surveyId = ( SELECT SurveyId FROM db.Survey WHERE SurveyGuid = surveyGUID);
INSERT INTO SurveyResponse (SurveyId, ResponseGuid) VALUES (@surveyId, UUID());
SELECT
ResponseGuid INTO responseGUID
FROM
db.SurveyResponse
WHERE
SurveyDetailId = last_insert_id();
END ??
DELIMITER ;
-- CALL spCreateSurveyResponse('Survey GUID here', @responseGUID);
-- SELECT @responseGUID;
当我从另一个SQL文件中调用过程时,SELECT @responseGUID始终返回Null。
答案 0 :(得分:1)
根据Jitendra的评论,我尝试更改参数的名称,并且成功了!
USE db;
DROP PROCEDURE IF EXISTS spCreateSurveyResponse;
DELIMITER ??
CREATE PROCEDURE spCreateSurveyResponse(
IN param_surveyGUID varchar(36),
OUT param_responseGUID varchar(36))
BEGIN
SET @surveyId = ( SELECT SurveyId FROM db.Survey WHERE SurveyGuid = param_surveyGUID);
INSERT INTO SurveyResponse (SurveyId, ResponseGuid) VALUES (@surveyId, UUID());
SELECT
ResponseGuid INTO param_responseGUID
FROM
db.SurveyResponse
WHERE
SurveyDetailId = last_insert_id();
END ??