MySQL stored procedures and common function code analysis

MySQL stored procedures and common function code analysis

The concept of mysql stored procedure:

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

The concept of mysql function:

A function is a SQL statement that performs a specific function. Functions are divided into built-in functions and user-defined functions (UDF).

The difference between MySQL stored procedures and functions

  • Stored procedures can have multiple in, out, and inout parameters, while functions only have input parameter types and cannot have in.
  • The functions implemented by stored procedures are more complex; while functions are more single-functional (targeted) and more targeted.
  • Stored procedures can return multiple values; stored functions can only return one value.
  • Stored procedures are generally executed independently; while stored functions can appear as components 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 and saved in the database to complete a specific function. The idea is to encapsulate and reuse code at the database SQL language level.

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

Creating custom functions

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

Note: 1. There can be no or multiple parameters.

2. There must be a return value, and only one.

3. If there is a SQL statement, put it between begin...end.

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

begin...end compound statement

Usually appears in stored procedures, functions, and triggers, which can contain one or more statements, each separated by ;.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • MySQL series five views, stored functions, stored procedures, triggers
  • Detailed discussion of MySQL stored procedures and stored functions
  • Detailed explanation of MySQL custom functions and stored procedures
  • Detailed explanation of creating stored procedures and functions in mysql

<<:  Detailed explanation of Nginx Rewrite usage scenarios and code examples

>>:  Analysis of Linux Zabbix custom monitoring and alarm implementation process

Recommend

Why is it not recommended to use index as key in react?

1. Compare the old virtual DOM with the new virtu...

Summary of shell's method for determining whether a variable is empty

How to determine whether a variable is empty in s...

In-depth analysis of Nginx virtual host

Table of contents 1. Virtual Host 1.1 Virtual Hos...

Detailed explanation of MySQL master-slave database construction method

This article describes how to build a MySQL maste...

Inspiring Design Examples of Glossy and Shiny Website Design

This collection showcases a number of outstanding ...

MySQL cross-table query and cross-table update

Friends who have some basic knowledge of SQL must...

Detailed explanation of the initialization mechanism in bash

Bash Initialization Files Interactive login shell...

Detailed tutorial on deploying Hadoop cluster using Docker

Recently, I want to build a hadoop test cluster i...

Vue Element front-end application development to obtain back-end data

Table of contents Overview 1. Acquisition and pro...

A brief discussion on the magical uses of CSS pseudo-elements and pseudo-classes

CSS plays a very important role in a web page. Wi...

25 Tools to Improve Website Usability and Conversion Rates

For a website, usability refers to whether users c...