当前位置:网站首页>Introduction and basic use of stored procedures
Introduction and basic use of stored procedures
2022-07-07 13:17:00 【Soup key TJ】
Catalog
The difference between stored procedures and functions ( Almost no difference )
Create and call stored procedures
Create and call stored procedures
View and delete of stored procedures
View all stored procedures in the database
Introduce
- Stored procedures and functions are compiled in advance and stored in the database a section SQL Collection of statements
benefits :
- Improve code reusability
- Reduce data transfer between database and application server , Increase of efficiency
- ( For databases , Later, it should be defined on one or more servers , Transmission later will definitely affect efficiency )
- Reduce business processing at the code level
The difference between stored procedures and functions ( Almost no difference )
- The storage function must have a return value
- A stored procedure may not return a value
Create and call stored procedures
Create stored procedure
- -- Modify the end separator
- delimiter $
- -- Create stored procedure
- create procedure Stored procedure name ( parameter list )
- begin
- SQL Statement list
- end$
- -- Modify the end separator
- delimiter ;
Calling stored procedure
- call Stored procedure name ( The actual parameter )
Examples demonstrate
Data preparation


-- Create student table CREATE TABLE student( id INT PRIMARY KEY auto_increment, -- Student id name VARCHAR(20), -- The student's name age INT, -- Student age gender VARCHAR(5), -- Student gender score INT -- Student achievement ); -- Add data INSERT INTO student VALUES (NULL,' Zhang San ',23,' male ',95),(NULL,' Li Si ',24,' male ',98),(NULL,' Wang Wu ',25,' Woman ',100),(NULL,' Zhao Liu ',26,' Woman ',90);Create and call stored procedures

-- establish stu_group() stored procedure , encapsulation Group query total score , And sort in ascending order according to the total score delimiter $ CREATE PROCEDURE stu_group() BEGIN SELECT gender,SUM(score) getsum FROM student GROUP BY gender ORDER BY getsum ASC; END$ delimiter ;
-- call stu_group() stored procedure CALL stu_group;View and delete of stored procedures
View all stored procedures in the database
- select * from mysql.proc where db=' Database name '
Delete stored procedure
- drop procedure [if exists] Stored procedure name
Example operation

-- see dp1 All stored procedures in the database SELECT * FROM mysql.proc WHERE db='dp1';
-- Delete stored procedure DROP PROCEDURE IF EXISTS stu_group;
边栏推荐
- Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
- Scrapy教程经典实战【新概念英语】
- 关于 appium 如何关闭 app (已解决)
- ClickHouse(03)ClickHouse怎么安装和部署
- 【无标题】
- Unity build error: the name "editorutility" does not exist in the current context
- PCAP学习笔记二:pcap4j源码笔记
- TPG x AIDU|AI领军人才招募计划进行中!
- Mongodb meets spark (for integration)
- How did Guotai Junan Securities open an account? Is it safe to open an account?
猜你喜欢

滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)

Cinnamon Applet 入门

Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules

Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~

ESP32构解工程添加组件

Introduce six open source protocols in detail (instructions for programmers)
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

数字ic设计——SPI

Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images

JS缓动动画原理教学(超细节)
随机推荐
Cookie and session comparison
How to reset Google browser? Google Chrome restore default settings?
[learning notes] agc010
Ogre入门尝鲜
MongoDB内部的存储原理
error LNK2019: 无法解析的外部符号
我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
高端了8年,雅迪如今怎么样?
学习突围2 - 关于高效学习的方法
数字ic设计——SPI
[untitled]
Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images
记一次 .NET 某新能源系统 线程疯涨 分析
PAcP learning note 3: pcap method description
Enterprise custom form engine solution (XII) -- experience code directory structure
Milkdown 控件图标
Differences between MySQL storage engine MyISAM and InnoDB
Mongodb slice summary
test
详细介绍六种开源协议(程序员须知)





