日期:2014-05-16  浏览次数:20708 次

mysql 在创建function出错 在线等 急用!求指教
BEGIN

  declare sqlt varchar(500);
  update mn_ammeter set STRADDRESS=replace(STRADDRESS,'\\','/') where STRADDRESS like '%\%';
   
  update mn_ammeterdisplaytype set strname=replace(strname,chr(10),'') where strname like '%'||chr(10)||'%';
   
  UPDATE mn_box set straddress = replace(straddress,chr(10 ),'') where straddress like '%'||chr(10)||'%';

  sqlt:='UPDATE '||tableName||' set '||fieldNmae|| ' = replace('||fieldNmae|| ',chr(10), ' ' ' ' ) where '||fieldNmae|| ' like ''%'||chr(10)||'%'';
   
  return 0;
end;

------解决方案--------------------
换成set sqlt='UPDATE '||tableName||' set '||fieldNmae|| ' = replace('||fieldNmae|| ',chr(10), ' ' ' ' ) where '||fieldNmae|| ' like ''%'||chr(10)||'%'';
看看
探讨
出现如下的错误

you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near ' sqlt:='UPDATE '||tableName||' set '||fieldNmae|| ' = ……

------解决方案--------------------
||->CONCAT
你是在MYSQL命令行下输入?
delimiter $$
create function ...
$$
delimiter ;
------解决方案--------------------
set @asql=你的SQL语句;
prepare stml from @asql;
execute stml;
------解决方案--------------------
引用set @asql=你的SQL语句;
prepare stml from @asql;
execute stml;