MSSQL and Mysql User-defined functions and stored procedures mysql and mssql user-defined functions without the cut string, such as in the input
(A, B, C ),
We need to obtain a column
Data
A
B
C
This is not included in the system itself. you need to define a function. first look at the custom function of MSSQL:
CREATE function StrSplit (@ c varchar (2000), @ split varchar (2) = ',')
Returns @ t table (col varchar (100 ))
As
Begin
While (charindex (@ split, @ c) <> 0)
Begin
Insert @ t (col) values (substring (@ c, 1, charindex (@ split, @ c)-1 ))
Set @ c = stuff (@ c, 1, charindex (@ split, @ c ),'')
End
Insert @ t (col) values (@ c)
Return
End
GO
When using
Select * from dbo. StrSplit ('52, 50, 55 ',','))
You can.
In MYSQL, I also want to use user-defined functions. However, the current version does not support returning functions of the table type, so I have to consider using stored procedures.
First, understand the statement for creating a temporary table in mysql:
Set global log_bin_trust_function_creators = 1;
DELIMITER $
Drop function if exists 'myf' $
Create definer = 'root' @ '%' FUNCTION 'myf' () RETURNS varchar (50) CHARSET utf8
Begin
Return concat ('-function ');
End $
DELIMITER;