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 use mysql custom functions

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly explains how to use the mysql custom function, the content is clear, interested friends can learn, I believe it will be helpful after reading.

What is a function: a function stores a series of sql statements that are executed at once when a function is called. So the function can reduce statement repetition. Note, however, that the function focuses on the return value and does not pay attention to the execution process, so some statements cannot be executed. So a function is not simply a collection of sql statements. Mysql functions have their own custom functions (defined functions). If you want to know more, you can refer to my other blog post: mysql common functions. Here we mainly introduce how to customize functions. Add: the difference between a function and a stored procedure: a function returns only one value, not a result set. The function emphasizes the return value, so the function does not allow multiple values to be returned, even in a query statement. -- No code: Not allowed to return a result set from a functioncreate function myf () returns int beginselect * from student;return 100 position end; function creation: syntax: create function function name ([parameter list]) returns data type begin sql statement; return value; format of end; parameter list is: variable name data type example:-- the simplest function with only one sql create function myselect2 () returns int return 666th select myselect2 () -- call the function-- create function myselect3 () returns intbegin declare c int; select id from class where cname= "python" into c; return c select myselect3 ();-- function create function myselect5 (name varchar (15)) with passed parameters returns intbegin declare c int; select id from class where cname=name into c; return cendscape select myselect5 ("python") Add: there can also be some special options, special options written after return, before begin, such as: comment: a description of the function and some options such as sql security, if you are interested, you can use Baidu on your own. There is no explanation here, only a point of knowledge is mentioned. Function call: you can directly use the function name () to call [that said, a result is returned. No result can be displayed without select in sql (so simply calling will report an error).] if you want to pass parameters, you can use the function name (parameter) call method [the functions called below are all created above. ]:-- No parameter call select myselect3 ();-pass parameter call select myselect5 ("python"); select * from class where id=myselect5 ("python"); function view: view function creation statement: show create function function name; view all functions: show function status [like 'pattern']; function modification: function modification can only modify some options such as comment, not internal sql statement and parameter list. Alter function function name option; function deletion: drop function function name; after reading the above, do you have a further understanding of how to use the mysql custom function? if you want to learn more, welcome to follow the industry information channel.

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

Wechat

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

12
Report