当前位置:网站首页>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;
边栏推荐
- Milkdown 控件图标
- Scripy tutorial classic practice [New Concept English]
- QQ的药,腾讯的票
- ISPRS2021/遥感影像云检测:一种地理信息驱动的方法和一种新的大规模遥感云/雪检测数据集
- OSI 七层模型
- [untitled]
- Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
- 【黑马早报】华为辟谣“军师”陈春花;恒驰5预售价17.9万元;周杰伦新专辑MV 3小时播放量破亿;法华寺回应万元月薪招人...
- 分布式事务解决方案
- 关于 appium 启动 app 后闪退的问题 - (已解决)
猜你喜欢
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
How to continue after handling chain interruption / sub chain error removed from scheduling
Introduce six open source protocols in detail (instructions for programmers)
QQ的药,腾讯的票
【无标题】
PACP学习笔记一:使用 PCAP 编程
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
高端了8年,雅迪如今怎么样?
About how appium closes apps (resolved)
基于鲲鹏原生安全,打造安全可信的计算平台
随机推荐
滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)
如何让electorn打开的新窗口在window任务栏上面
详细介绍六种开源协议(程序员须知)
飞桨EasyDL实操范例:工业零件划痕自动识别
Isprs2021/ remote sensing image cloud detection: a geographic information driven method and a new large-scale remote sensing cloud / snow detection data set
Cookie and session comparison
Mongodb meets spark (for integration)
【无标题】
User management summary of mongodb
Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
Day26 IP query items
聊聊伪共享
一文读懂数仓中的pg_stat
《开源圆桌派》第十一期“冰与火之歌”——如何平衡开源与安全间的天然矛盾?
Simple and easy-to-use code specification
分屏bug 小记
ESP32 ① 编译环境
MySQL入门尝鲜
ESP32构解工程添加组件
COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~