Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write mysql function

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following is mainly about how to write mysql functions. I hope these contents can bring you practical use, which is also the main purpose of my article on how to write mysql functions. All right, don't talk too much nonsense, let's just read the following.

The functions in mysql are written as follows:

Create function functionName ([parm type], [parm1 type], …)

Returns type

Begin

Statement

Return value

End

The above is the template for writing the mysql function. In functions, you can't use select statements to print data, but use select to query data and assign values to variables, which is fine. A function must have a return value.

In mysql, functions can be used in select for data processing.

Of course, various types of variables can be defined in the function, such as bigint,longtext,varchar,int and so on, as well as data of cursor type.

After writing the mysql function, if an error occurs to create the function

[Err] 1418-This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)

You need to execute the following statement:

Set global log_bin_trust_function_creators=1

The cause of this problem is the security of the master-slave equipment.

Example of a function:

Create FUNCTION functionTest (p_con VARCHAR)

RETURNS VARCHAR (400)

BEGIN

DECLARE v_con VARCHAR (400)

Set v_con = p_con

SELECT p_con into v_con

Return v_con

End

Select functionTest ('baiduc')

For the above about how to write mysql functions, we do not find it very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report