即使根据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行但不返回任何内容。
答案 0 :(得分:2)
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
答案 1 :(得分:0)
你有错误的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;
试试这个。如果您还有其他需要,请告诉我。