[英]Syntax Error in MySQL stored procedure
即使根据where子句有48行,下面的SP也没有给出任何结果
BEGIN
DECLARE SelectClause VARCHAR(2000);
if v_mode='SearchByString' then
SET SelectClause ='select SURVEY_USER.username,SURVEY.* from SURVEY, SURVEY_USER';
if v_SearchString is not null then
SET SelectClause=CONCAT(@SelectClause,' where ');
Set SelectClause=CONCAT(@SelectClause,v_SearchString);
end if;
SET SelectClause=CONCAT(@SelectClause,' order by SURVEY.created_date DESC;') ;
select SelectClause;
SET @query = SelectClause;
PREPARE stmt FROM @query;
EXECUTE stmt;
select stmt;
end if;
END
我尝试了很多,但没有遇到任何问题。 我也试过select子句在各个地方打印命令,无法打印它。 请给我一些解决方案。 我传递的参数是v_mode ='SearhByString'v_SearchString ='SURVEY_USER.username = chiragfanse'
它应返回48行但不返回任何内容。
BEGIN
DECLARE SelectClause VARCHAR(2000);
IF v_mode = 'SearchString' THEN
SET SelectClause = CONCAT('select SURVEY_USER.username,SURVEY.* from SURVEY, SURVEY_USER');
IF SearchString IS NOT NULL THEN
SET SelectClause = CONCAT(SelectClause, ' where ', SearchString);
END IF;
SET SelectClause = CONCAT(SelectClause, ' order by SURVEY.created_date DESC;');
SET @query = SelectClause;
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END
你有错误的concat函数。 尝试这个。
if v_mode='SearchString' then
DECLARE @SelectClause varchar(2000);
SET @SelectClause =CONCAT(select (SURVEY_USER.username,SURVEY.*) from SURVEY, 'SURVEY_USER');
if SearchString is not null then
@SelectClause=CONCAT(@SelectClause, 'where' ,SearchString);
end if;
SET @SelectClause=@SelectClause
order by SURVEY.created_date DESC
execute(@SelectClause)
end if;
尝试这个。 需要帮助请叫我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.