上面的报错,是在MySQL里执行动态拼接SQL后报错的。
-- 先定义两段SQL set @update_sql_fm=concat('update ads_gcl3e_patient_',@base_group_short_name,'_detail1 t1 join temp_gcl3e_record_list tmp on t1.report_info_id=tmp.report_info_id left join (',@select_sql_fm,') t2 on t1.report_info_id=t2.report_info_id ',@set_sql); -- 满足分母+分子 set @update_sql_fz=concat('update ads_gcl3e_patient_',@base_group_short_name,'_detail1 t1 join temp_gcl3e_record_list tmp on t1.report_info_id=tmp.report_info_id left join (',@select_sql_fz,') t2 on t1.report_info_id=t2.report_info_id ',@set_sql); -- 拼接两段SQL后进行提交执行 SET @sql = concat(@update_sql_fm,@update_sql_fz); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
执行报错: Unknown prepared statement handler (stmt2) given to DEALLOCATE PREPARE
查询ChatGpt后,提示
查看名称和语法并没有问题哦。
尝试注释掉DEALLOCATE PREPARE语句后,又报新的错: Unknown prepared statement handler (stmt2) given to EXECUTE
怀疑跟要执行的SQL有关系。难道是只能提交一段SQL?
-- 执行分母SQL, 一次prepare只能提交一段SQL,两段Update会报错 SET @sql1 = @update_sql_fm; PREPARE stmt1 FROM @sql1; EXECUTE stmt1; DEALLOCATE PREPARE stmt1; -- 执行分子SQL SET @sql2 = @update_sql_fz; PREPARE stmt2 FROM @sql2; EXECUTE stmt2; DEALLOCATE PREPARE stmt2;
Binggo! 解决!
每次只能提交一个SQL任务!多个,拆分一下好了!
每天进步一点点