In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how mysql creates storage functions. Xiao Bian thinks it is quite practical, so share it for everyone to make a reference. Let's follow the editor and have a look.
A stored function is a snippet of code consisting of SQL statements and procedural statements that can be called by applications and other SQL statements. In MySQL, a stored function can be created by the CREATE FUNCTION statement.
Storage function is a special type of storage program that returns a single value. Next, we will introduce in detail how to create a storage function in MySQL, which has certain reference value and hopes to help everyone.
stored function
Stored functions are similar to stored procedures in that they are code snippets composed of SQL statements and procedural statements that can be invoked by applications and other SQL statements. Since the stored function itself is an output function, it cannot have output parameters, and it can be called directly without a call statement.
Creation of Storage Functions
syntax
CREATE FUNCTION function_name(param1,param2,…) RETURNS datatype [NOT] DETERMINISTIC statementsSQL
Syntax analysis:
The CREATE FUNCTION clause is followed by the name of the specified stored function
(param1,param2,…): Represents all parameters of the stored function, which by default are IN parameters. You cannot specify IN, OUT, or INOUT modifiers for parameters.
RETURNS datatype: indicates the data type of the return value, which can be any valid MySQL datatype
[NOT]TERMINISTIC: Indicates that the result is indeterminate and that the same input may yield different outputs. If no value is specified, the default is [NOT] DETERMINATION
SQL: Program body
Example: Create a stored function named demo that returns the query result of a SELECT statement with a string type value. The code is as follows:
mysql> DELIMITER //mysql> CREATE FUNCTION demo() -> RETURNS CHAR(50) -> RETURN ( SELECT s_name FROM suppliers WHERE s_call='48075'); -> //Query OK, 0 rows affected (0.11 sec)mysql> DELIMITER ; Thank you for reading! About mysql how to create a storage function to share here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge. If you think the article is good, you can share it so that more people can see 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.