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 mysql creates stored functions

2025-01-19 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.

Share To

Database

Wechat

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

12
Report