sking 发表于 2010-7-11 10:23:52

◆请教关于MySql创建Function的问题,急!◆

以下这段脚本报错,请高手指教,谢谢!

create function fun_getCityByOid(oid int,split varchar(10)) returns varchar(400)
    begin
      declare done int default 0;
      declare result varchar(1000);
      declare retStr varchar(100);
      declare cur cursor for
            select d.cityName from t_order a
            inner join t_order_rec_detail b on a.oid = b.oid
            inner join t_reciever c on b.rid = c.rid
            inner join t_city d on c.cityid = d.cityid
            where a.oid = oid
            group by c.cityid;
      DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
      set result = '';
      open cur;
      repeat
      fetch cur into retStr;
            if not done then
            set result = concat(result, retStr, split);
            end if;
      UNTIL done end repeat;
      close cur;
      return substring(result,1,char_length(result)-1);
    end;


报如下错误信息:

错误代码: 1064
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 '' at line 3
(耗费 0 ms)

错误代码: 1064
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 'declare result varchar(1000)' at line 1
(耗费 0 ms)

错误代码: 1064
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 'declare retStr varchar(100)' at line 1
(耗费 0 ms)

错误代码: 1064
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 'declare cur cursor for
            select d.cityName from t_order a
            inner join t_ord' at line 1
(耗费 0 ms)

错误代码: 1064
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 'DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1' at line 1
(耗费 0 ms)

错误代码: 1193
Unknown system variable 'result'
(耗费 0 ms)

错误代码: 1064
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 'open cur' at line 1
(耗费 0 ms)

错误代码: 1064
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 'repeat
      fetch cur into retStr' at line 1
(耗费 0 ms)

错误代码: 1064
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 'if not done then
            set result = concat(result, retStr, split)' at line 1
(耗费 0 ms)

错误代码: 1064
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 'end if' at line 1
(耗费 16 ms)

错误代码: 1064
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 'UNTIL done end repeat' at line 1
(耗费 0 ms)

错误代码: 1064
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 'close cur' at line 1
(耗费 0 ms)

错误代码: 1064
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 'return substring(result,1,char_length(result)-1)' at line 1
(耗费 0 ms)

错误代码: 1064
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 'end' at line 1
(耗费 0 ms)
页: [1]
查看完整版本: ◆请教关于MySql创建Function的问题,急!◆