Home > database >  MYSQL custom function at 1064 fault
MYSQL custom function at 1064 fault

Time:09-27

Do you want to be a string segmentation custom function, the result is always an error, please help to look at, thank you!
 CREATE function GetCharIndexNum (` @ findstring ` varchar (255), ` @ string ` varchar (255)) 
Returns the int

The BEGIN
Declare ` @ location ` int.
Declare ` @ num ` int.

The set @ num=0;
The set @ location=charindex (@ findstring, @ string);
While @ the location & gt; 0 do
The begin
The set @ num=@ num + 1;
Set @ string=the substring (@ string, @ location + 1, len (@ string));
The set @ location=charindex (@ findstring, @ string);

End
Return the @ num

END

CodePudding user response:

Delimiter/
.
Your function to create statement (note: your statement "return @ num" missing semicolon ";"

.
Delimiter.

CodePudding user response:

The building Lord what database, what is error?

CodePudding user response:

refer to the second floor ACMAIN_CHM response:
what the original poster with the database, what is error?


refer to the second floor ACMAIN_CHM response:
what the original poster with the database, what is error?
the MYSQL database

CodePudding user response:

reference 1st floor jinsenhome response:
delimiter/
.
Your function to create statement (note: your statement "return @ num" missing semicolon ";"

.
Delimiter.
added also not line

CodePudding user response:

The CONTAINS the SQL are that the routine does not contain statements that read or write data.
This is the default if none of these characteristics is given explicitly. The Examples of to statements are SET @ x=1 or DO RELEASE_LOCK (' ABC '), which execute but neither read nor write.
The CONTAINS the SQL said subroutine statement does not include the read or write data,

NO SQL said subroutine does not contain the SQL statement,

READS SQL DATA said subroutine statements contain read DATA, but does not contain DATA written statements,

MODIFIES SQL DATA said subroutine statements contain written DATA,

If these characteristics is not clearly given, the default is the CONTAINS SQL,

CodePudding user response:

You sent two posts of the same question? I have received the
Compiled by the
 
The CREATE FUNCTION ` GetCharIndexNum ` (` findstring ` VARCHAR (255),
` string ` VARCHAR (255))
RETURNS the INT
NO SQL
DETERMINISTIC
The BEGIN
DECLARE ` location ` INT.
DECLARE ` num ` INT.

The SET of num=0;
SET the location=charindex (findstring, string);

WHILE the location & gt; 0 DO
The SET num=num + 1;
SET the string=the Substring (string, the location + 1, len (string));
SET the location=Charindex (findstring, string);
END WHILE;

RETURN num.
END;

  • Related