在写存储过程中使用了concat()拼接动态sql,但是在页面中报错如下:存储过程如下:
set @p_start_date = start_date;
set @p_end_date = end_date;
set @p_server_id = server_id; if country = 'all' then set @v_sql= concat('select 
stat_time,
SUM(pay_dru) as pay_dru, 
SUM(second_day) as second_day,
SUM(third_day) as third_day,
SUM(four_day) as four_day,
SUM(five_day) as five_day,
SUM(six_day) as six_day,
SUM(seventh_day) as seventh_day,
SUM(eight_day) as eight_day,
SUM(fourteen_day) as fourteen_day,
SUM(thirtieth_day) as thirtieth_day,
SUM(first_day_price) as first_day_price,
SUM(second_day_price) as second_day_price,
SUM(third_day_price) as third_day_price,
SUM(four_day_price) as four_day_price,
SUM(fifteen_day_price) as fifteen_day_price,
SUM(fifteen_day) as fifteen_day,
SUM(five_day_price) as five_day_price,
SUM(six_day_price) as six_day_price,
SUM(seventh_day_price) as seventh_day_price,
SUM(eight_day_price) as eight_day_price,
SUM(fourteen_day_price) as fourteen_day_price,
SUM(thirtieth_day_price) as thirtieth_day_price,
SUM(ninety_day_price) as ninety_day_price,
SUM(ninety_day) as ninety_day
from stat_pay_remain where (stat_time between @p_start_date and date_add(@p_end_date, interval 1 day)) 
and (server_id = @p_server_id) 
GROUP BY stat_time
order by stat_time desc;');
prepare stmt from @v_sql;
EXECUTE stmt;
deallocate prepare stmt;

ELSE

set @v_sql= concat('select 
stat_time,
SUM(pay_dru) as pay_dru, 
SUM(second_day) as second_day,
SUM(third_day) as third_day,
SUM(four_day) as four_day,
SUM(five_day) as five_day,
SUM(six_day) as six_day,
SUM(seventh_day) as seventh_day,
SUM(eight_day) as eight_day,
SUM(fourteen_day) as fourteen_day,
SUM(fifteen_day) as fifteen_day,
SUM(thirtieth_day) as thirtieth_day,
SUM(first_day_price) as first_day_price,
SUM(second_day_price) as second_day_price,
SUM(third_day_price) as third_day_price,
SUM(four_day_price) as four_day_price,
SUM(five_day_price) as five_day_price,
SUM(six_day_price) as six_day_price,
SUM(seventh_day_price) as seventh_day_price,
SUM(eight_day_price) as eight_day_price,
SUM(fourteen_day_price) as fourteen_day_price,
SUM(fifteen_day_price) as fifteen_day_price,
SUM(thirtieth_day_price) as thirtieth_day_price,
SUM(ninety_day_price) as ninety_day_price,
SUM(ninety_day) as ninety_day
from stat_pay_remain where (stat_time between @p_start_date and date_add(@p_end_date, interval 1 day)) 
and (server_id = @p_server_id) 
and (country in (',country,'))
GROUP BY stat_time
order by stat_time desc;');
prepare stmt from @v_sql;
EXECUTE stmt;
deallocate prepare stmt;
end if; COMMIT;
不知道有没有小伙伴遇到过这个问题没有?求解决方案!