想做一個字串分割自定義函式,結果老是報錯,請幫助看一下,謝謝!
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
uj5u.com熱心網友回復:
delimiter /................
你的函式創建陳述句 (注意:你的陳述句中 “return @num ” 漏掉了分號";"
/
................
delimiter ;
uj5u.com熱心網友回復:
樓主用的什么資料庫,錯誤提示是什么?uj5u.com熱心網友回復:
MYSQL資料庫
uj5u.com熱心網友回復:
加了也不行呢uj5u.com熱心網友回復:
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。
uj5u.com熱心網友回復:
你的同一個問題怎么發了兩個帖子?我都收到吧
編譯通過了
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;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/85502.html
標籤:MySQL
上一篇:自定義函式問題
