How to create a function in mysql

coldplay.xixi
Release: 2020-09-29 14:47:15
Original
12007 people have browsed it

How to create a function in mysql: first check whether the function of creating a function is turned on; then if the value at Value is OFF, you need to turn it on; then when creating the function, first select the database; finally test it .

How to create a function in mysql

More related free learning recommendations:mysql tutorial(video)

How to create a function in mysql:

1. Check whether the function of creating a function is turned on:

mysql> show variables like '%func%'; +-----------------------------------------+-------+ | Variable_name | Value | +-----------------------------------------+-------+ | log_bin_trust_function_creators | ON | +-----------------------------------------+-------+ 1 row in set (0.02 sec)
Copy after login

2. If the value at Value is OFF, you need to turn it on.

mysql> set global log_bin_trust_function_creators=1;
Copy after login

3. When creating a function, select the database first.

mysql> use xxx; Database changed delimiter $$是设置 $$为命令终止符号,代替分号,因为分号在begin...end中会用到; mysql> delimiter $$ CREATE FUNCTION first_func(param1 varchar(5),parmam2 varchar(5),param3 varchar(10)) RETURNS TINYINT BEGIN RETURN 1; END
Copy after login

After the function is successfully created, the semicolon must be restored as the command termination symbol.

mysql> delimiter ;

4. Test:

mysql> select first_func('aaa','bbb','ccc'); +-------------------------------+ | first_func('aaa','bbb','ccc') | +-------------------------------+ | 1 | +-------------------------------+ 1 row in set (0.47 sec)
Copy after login

5. Delete function:

mysql> drop function first_func ; Query OK, 0 rows affected (0.11 sec)
Copy after login

6. View function

1 ) show function status

Display basic information of all functions in the database

2) View a specific function

mysql>show create function function;
Copy after login

The above is the detailed content of How to create a function in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!