Create user-defined functions in MySQL

Source: Internet
Author: User

To prevent the mid-process output produced by semicolons, define a separator. The following is an official MySQL example: Use two dollar signs $ as the separator. The following sectionCodeIt is to create a prototype of a user-defined MySQL function, which can be modified on this basis, so that the creation of the function will not produce many errors.

Set global log_bin_trust_function_creators = 1; -- enable bin_log copy function Creation
Drop function if exists hello; -- delete an existing
Delimiter $ -- defines the delimiter, which must be available, but not $
Create Function Hello (s varchar (30) -- used for multiple parameters. The split parameter must be of the MySQL column type.
Returns varchar (255) -- specifies the return value type. If you are not sure about the length of the returned text, you can use text
Begin
Declare STR varchar (255) default 'hello'; -- defines a variable and specifies the default value.
Set STR = Concat (STR, S); -- set the value of the edge variable.
Return STR; -- Return Value
End $ -- note that the end contains the separator defined earlier.
delimiter $ -- okay, this is the end.

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.