MYSQL自定义函数报1064错

yuzhifu1 2018-07-04 07:08:30
想做一个字符串分割自定义函数,结果老是报错,请帮助看一下,谢谢!
CREATE  function GetCharIndexNum (`@findstring` varchar(255),`@string` varchar(255))
returns int

BEGIN
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
...全文
770 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
生命沉思者 2018-07-05
  • 打赏
  • 举报
回复
你的同一个问题怎么发了两个帖子?我都收到吧
编译通过了

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;

crynono 2018-07-05
  • 打赏
  • 举报
回复
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。
yuzhifu1 2018-07-05
  • 打赏
  • 举报
回复
引用 1 楼 jinsenhome 的回复:
delimiter /
................
你的函数创建语句 (注意:你的语句中 “return @num ” 漏掉了分号";"
/
................
delimiter ;
加了也不行呢
yuzhifu1 2018-07-05
  • 打赏
  • 举报
回复
引用 2 楼 ACMAIN_CHM 的回复:
楼主用的什么数据库,错误提示是什么?


引用 2 楼 ACMAIN_CHM 的回复:
楼主用的什么数据库,错误提示是什么?
MYSQL数据库
ACMAIN_CHM 2018-07-04
  • 打赏
  • 举报
回复
楼主用的什么数据库,错误提示是什么?
jinsenhome 2018-07-04
  • 打赏
  • 举报
回复
delimiter /
................
你的函数创建语句 (注意:你的语句中 “return @num ” 漏掉了分号";"
/
................
delimiter ;

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧