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

Nginx learning how to build a file hotlink protection service example

Preface Everyone knows that many sites now charge...

Tutorial on downloading, installing, configuring and using MySQL under Windows

Overview of MySQL MySQL is a relational database ...

Solution to forgetting the password of the pagoda panel in Linux 3.X/4.x/5.x

Enter ssh and enter the following command to rese...

Table td picture horizontally and vertically centered code

Html code: Copy code The code is as follows: <t...

Method of iframe adaptation in web responsive layout

Problem <br />In responsive layout, we shou...

Getting Started Tutorial for Beginners ④: How to bind subdirectories

To understand what this means, we must first know ...

JavaScript+html to implement front-end page sliding verification

This article shares the specific code of JavaScri...

HTML cellpadding and cellspacing attributes explained in pictures

Cell -- the content of the table Cell margin (tabl...

How to configure two or more sites using Apache Web server

How to host two or more sites on the popular and ...

How to shrink the log file in MYSQL SERVER

The transaction log records the operations on the...

Regular expression usage in CSS selectors

Yes, CSS has regular expressions too (Amen) Two p...

What does the n after int(n) in MySQL mean?

You may already know that the length 1 of int(1) ...

Complete steps to use vue-router in vue3

Preface Managing routing is an essential feature ...