MySQL Stored Procedure with Prepared Statement does not work -
MySQL Stored Procedure with Prepared Statement does not work -
i have next stored procedure:
create procedure getlastvalueautomaticshelter(in fieldname varchar(30), position_number int) begin set @query = concat('select * automatic_changes where',fieldname,'is not null , p_id=?'); prepare stmt @query; set @position_number=position_number; execute stmt using @position_number; deallocate prepare stmt; end
then running it:
mysql> phone call getlastvalueautomaticshelter('current_level', 500)//
and getting next error:
error 1064 (42000): have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'not n ull , p_id=?' @ line 1
any ideas? thanks.
you need add together spaces in there:
set @query = concat('select * automatic_changes ',fieldname,' not null , p_id=?'); /* right ^ here....and ^ here*/
otherwise final query might this:
select * automatic_changes wherecolumnameis not null , p_id='whatever';
you thought :)
mysql stored-procedures prepared-statement
Comments
Post a Comment