About mysql user-defined functions

Source: Internet
Author: User
Because of work requirements, you need to write a mysql custom number of rows, as shown below: DELIMITER $ DROPFUNCTIONIFEXISTS 'onlinefunction '$ CREATEFUNCTION 'onlinefunction' (rrrrVARCHAR (50) RETURNSVARCHAR (255) BEGINIF (rrrronline) THENRETURN goes live; ENDIF; END $ DELIMITER;

Because of work requirements, you need to write a mysql custom number of rows, as follows: DELIMITER $ drop function if exists 'onlinefunction '$ create function 'onlinefunction' (rrrr VARCHAR (50 )) returns varchar (255) BEGINIF (rrrr = 'online') then return 'online'; end if; END $ DELIMITER;

To customize the number of mysql rows

DELIMITER $ drop function if exists 'onlinefunction '$ create function 'onlinefunction' (rrrr VARCHAR (50) returns varchar (255) BEGINIF (rrrr = 'online ') then return 'online'; end if; END $ DELIMITER;

The first line of DELIMITER defines an end identifier. because MySQL uses a semicolon as the end character of an SQL statement by default, and a semicolon is used inside the function body, it will conflict with the default SQL end character, therefore, you must first define another symbol as the SQL Terminator. If this definition is not added...

Error code: 1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'end' at line 1

The second line is to delete the class with the same name, otherwise it will...

Error code: 1304 FUNCTION onlineFunction already exists

Row 3 function name, function variable, and return type

The fourth line, begin, is the start and corresponds to end $.

The fifth line is the if judgment Statement, in the format

if(...) then....;elseif....;else.....;end if;return ..;

Sometimes mysql cannot create a UDF because function 2 is not enabled.

Enter the show variables like '% func %' command.

The status of log_bin_trust_function_creators is displayed. If it is OFF, the UDF function is disabled.

Enter the command set global log_bin_trust_function_creators = 1;

You can enable the UDF function for log_bin_trust_function_creators.

However, this setting is a temporary solution, because the status changes to OFF after mysql is automatically restarted, so you need

Add the "-- log-bin-trust-function-creators = 1" parameter when the service is started.
Or add log-bin-trust-function-creators = 1 in the [mysqld] section of my. ini (my. cnf.

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.