Get the App
SLTechnology News&Howtos  ›  Database  › 

A case study of MySQL stored procedures and functions

Shulou Source: shulou.com Published: 2022-06-01 04:37:01 09月15日 Update

This article will explain in detail the case study of MySQL stored procedures and functions. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The concept of mysql stored procedures:

A segment of SQL code stored in a database that can perform specific tasks (queries and updates).

The concept of mysql function:

Functions are SQL statements that perform specific functions. Functions are divided into built-in functions and custom functions (user-defined function UDF).

The difference between MySQL stored procedures and functions

Stored procedures can have multiple in,out,inout parameters, while functions have only input parameter types and cannot take in. The functions implemented by stored procedures are more complex; the single functionality (pertinence) of functions is stronger. Stored procedures can return multiple values; stored functions can only have one return value. Stored procedures are generally executed independently; stored functions can appear as part of other sql statements. Stored procedures can call stored functions. Functions cannot call stored procedures.

A stored procedure is a set of sql statements that are compiled, created and saved in a database to complete a specific function. The idea is the code encapsulation and reuse at the database sql language level.

Note: in refers to input parameters and out refers to output parameters

Create a custom function

Syntax format: create function name (parameter type, parameter type...) Returns type return expression value

Note: 1. Parameters can be absent or have more than one.

two。 There must be a return value and only one.

3. If there is a SQL statement, put it in the middle of the begin...end.

4. If you don't add determministic, you will report an error (I don't know how to solve it)

Begin...end compound statement

It usually occurs in stored procedures, functions, and triggers, which can contain one or more statements, each separated by.

This is the end of the case study on MySQL stored procedures and functions. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Functions storage procedures parameters statements functions multiple types data databases cases case studies analysis code only more concepts articles input good Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker macOS Shulou Technology Microsoft Shulou Information