当前位置:网站首页>[MySQL] use of stored procedures
[MySQL] use of stored procedures
2022-06-11 10:25:00 【Xiao AI ~】
1. Use of stored procedures
Before using a stored procedure, learn what a stored procedure is .
Stored procedures and functions
Stored procedures and functions : Be similar to java The method in
benefits :
1. Improve code reuse
2. Simplified operation
meaning : A set of precompiled sql Collection of statements , Understand batch processing statements
1. Improve code reuse
2. Simplified operation
3. The number of compilations is reduced and the connection to the database server is reduced , Improved efficiency .
The syntax of the stored procedure is :
One 、 Create Syntax
CREATE PROCEDURE helloWord()
BEGIN
END
Be careful :
1. The parameter list consists of three parts
Parameter mode Parameter name Parameter type
give an example :
IN stuname VARCHAR(20)
Parameter mode :
IN : This parameter can be used as input , That is, the parameter requires the caller to pass in a value
OUT: This generation can be used as an output , That is, the parameter can be used as the return value
INOUT: Changing parameters can be input or output
1. establish in Stored procedures for patterns
CREATE PROCEDURE myp2(IN `name` VARCHAR(20))
BEGIN
DECLARE res INT DEFAULT 0; # Define variables and initialize
SELECT COUNT(*) INTO res # assignment
FROM tab_identity
WHERE tab_identity.`NAME`=`name`;
SELECT IF(res>0,' success ',' Failure ') result ;
END
# Calling stored procedure
CALL myp2(' Zhang Sanfeng ');
2. establish out Stored procedures for patterns
CREATE PROCEDURE myp4(IN `id` BIGINT(20),OUT boyName VARCHAR(20))
BEGIN
SELECT ide.`NAME` INTO boyName
FROM tab_identity ide
WHERE ide.`ID`=id;
END
# Calling stored procedure
CALL myp4(11,@bName);
SELECT @bName;
3. Create a inout Stored procedures for patterns
# Create a inOut Stored procedures for patterns
CREATE PROCEDURE myp6(INOUT `id` INT)
BEGIN
SET id=id*5;
END
# with inout A variable needs to be created before the stored procedure call of
SET @a=10;
CALL myp6(@a);
SELECT @a;
边栏推荐
- Browserfetcher class for getting started with puppeter
- 远程监控项目离线日志说明书
- Internet of things security in the era of remote work
- Dimension types for different CV tasks
- Mysql-- index
- About CI framework batch export to compressed file
- Cas de rectification du CEM rayonné par des équipements électroniques
- Série de démarrage C # (XI) - - tableaux multidimensionnels
- Pagoda panel backup and recovery data
- WordPress website backup
猜你喜欢

用真金做的电路板——金手指

Datagrip 2022, datagrip function

Ugui mouse click diffusion UI effect

【CV基础】颜色:RGB/HSV/Lab

ZigBee模块无线传输星形拓扑组网结构简介

Internet of things security in the era of remote work

What is the SOA or ASO of MOSFET?

详述用网络分析仪测量DC-DC和PDN

有哪些ABAP关键字和语法,到了ABAP云环境上就没办法用了?

Detail measurement of DC-DC and PDN with network analyzer
随机推荐
【torch】: 并行训练并且可以动态设置第一个gpu的batch size
Differences between beanfactory and factorybean
FPGA infrastructure [reference ug998]
ZigBee模块通信协议的树形拓扑组网结构
Datagrip 2022, datagrip function
Mysql--索引
Knowledge drop - personality analysis - four types of method
使用bat向文件的第一行中写入内容
Address of my bookmark
Cas de rectification du CEM rayonné par des équipements électroniques
【高并发】关于线程池,蚂蚁金服面试官问了我这些内容!!
Internet of things security in the era of remote work
NGUI,冷却效果
Beginning simple blog emlog theme template V3
知识点滴 - 性格分析-四类法
Function and function of wandfluh proportional valve
【DBSCAN】DBSCAN实例
Use bat to write to the first line of the file
Preview component packaging graphic tutorial in cadence OrCAD capture schematic design interface
C#入門系列(十一) -- 多維數組