我有一个存储过程中超过 540 个字符的 sql select 语句
我已将其放入名为l_final_query
type的变量中LONGTEXT
现在,当我执行此查询时:
PREPARE stmt7 FROM @l_final_query;
EXECUTE stmt7;
它失败。但是,当我开始删除 sql 的最后一个 order by 子句时,它可以工作。我过去曾遇到过用于执行的变量大小和变通方法的问题。但现在我没有解决方法。我试图将该order by
子句放在另一个变量l_final_query2
中,并将其与大选择连接起来,但这也不起作用。
这是附加到变量并被执行的 sql。我已经包含了 order by 子句:
set @l_final_query = concat("SELECT a.project_code as projectCode, a.project_name as projectName, a.project_creation_date as projectCreationDate, a.project_end_date as projectEndDate, a.project_status as projectStatus, count(c.project_code) as num from projects a inner join ", l_table_name, " b on a.project_name like concat(\"%\",b.expertise_desc,\"%\") OR a.project_description like concat(\"%\",b.expertise_desc,\"%\") left join project_ids c on c.project_code = a.project_code group by a.project_code order by a.project_status, a.project_creation_date desc");