想做一个字符串分割自定义函数,结果老是报错,请帮助看一下,谢谢!
CREATE  function GetCharIndexNum (`@findstring` varchar(255),`@string` varchar(255))
returns intBEGIN
   declare `@location` int ; 
   declare    `@num` int ;
    
   set @num =0;
   set @location = charindex (@findstring,@string);
   while @location >0  do
      begin
      set @num =@num +1;
      set @string =substring(@string,@location+1,len(@string));
      set @location = charindex (@findstring,@string);    end
return @num END

解决方案 »

  1.   

    delimiter /
    ................
    你的函数创建语句 (注意:你的语句中 “return @num ” 漏掉了分号";"
    /
    ................
    delimiter ;
      

  2.   


    MYSQL数据库
      

  3.   

    CONTAINS SQL indicates that the routine does not contain statements that read or write data. 
    This is the default if none of these characteristics is given explicitly. Examples of such statements are SET @x = 1 or DO RELEASE_LOCK('abc'), which execute but neither read nor write data.
    CONTAINS SQL表示子程序不包含读或写数据的语句。NO SQL表示子程序不包含SQL语句。READS SQL DATA表示子程序包含读数据的语句,但不包含写数据的语句。MODIFIES SQL DATA表示子程序包含写数据的语句。如果这些特征没有明确给定,默认的是CONTAINS SQL。
      

  4.   

    你的同一个问题怎么发了两个帖子?我都收到吧
    编译通过了CREATE FUNCTION `GetCharIndexNum`(`findstring` VARCHAR(255),
                                      `string`     VARCHAR(255))
    RETURNS INT
    NO SQL
    DETERMINISTIC
    BEGIN
      DECLARE `location` INT;
      DECLARE `num` INT;  SET num =0;
      SET location = charindex (findstring, string);  WHILE location > 0 DO
        SET num = num +1;
        SET string = Substring(string, location+1, len(string));
        SET location = Charindex (findstring, string);
      END WHILE;  RETURN num;
    END;