Create a user-defined function in mysql _ MySQL

Source: Internet
Author: User
Create user-defined functions in mysql Create a user-defined function in mysql _ MySQL

To prevent the mid-process output produced by semicolons, define a separator. here, we use the mysql official example: use two dollar signs $ as the separator, the following code is used to create a prototype of a user-defined mysql function. you can modify it on this basis so that the creation of a function will not produce many errors.


Set global log_bin_trust_function_creators = 1; -- enable the bin_log replication FUNCTION to create the drop function if exists hello; -- delete an existing DELIMITER $ -- defines the DELIMITER, which must be, it may not be $ create function hello (s varchar (30) -- Multiple parameters are used. the split parameter type must be the returns varchar (255) type existing in the mysql column) -- specify the return value type. if you are not sure about the length of the returned text, you can use textBEGIN DECLARE str varchar (255) default 'hello'; -- to define a variable, you can specify the default value SET str = concat (str, s); -- SET the value of the edge variable RETURN str; -- RETURN value END $ -- be sure to see clearly The end is followed by the DELIMITER $ defined earlier.

The above is the content for mysql to create user-defined function _ MySQL. For more information, please follow the PHP Chinese network (www.php1.cn )!

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.