MSSQL and Mysql User-defined functions and stored procedures _ MySQL

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.