日期:2014-05-16 浏览次数:21072 次
ALTER FUNCTION fu_GetPhoneNamesByOfficeID ( OfficeID int ) RETURNS varchar(250) AS BEGIN declare Str varchar(250); declare PhoneName varchar(50); declare isFirst bit; set Str=''; set isFirst=0; declare name_cur cursor for select concat(p.手机品牌, ' ' , p.手机型号 ) from TB_BAS_Office_Model m inner join phoneInfo p on p.flngID=m.flngPhoneID and m.flngOfficeID=@OfficeID order by p.手机品牌, p.flngID desc; open name_cur; fetch name_cur into PhoneName; repeat if isFirst=0 then set isFirst=1; set Str=concat(Str, PhoneName); else set Str=concat(Str ,',',PhoneName); end if fetch name_cur into PhoneName; until 0 end repeat ; close name_cur ; return Str; End
------解决方案--------------------
DELIMITER $$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
FUNCTION `jnxp`.`fu_GetPhoneNamesByOfficeID`()
RETURNS TYPE
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
END$$
DELIMITER ;
转义用的 必须用上