当前位置:网站首页>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;
边栏推荐
猜你喜欢
飞桨EasyDL实操范例:工业零件划痕自动识别
自定义线程池拒绝策略
MySQL master-slave replication
How to continue after handling chain interruption / sub chain error removed from scheduling
【Presto Profile系列】Timeline使用
【无标题】
Practical example of propeller easydl: automatic scratch recognition of industrial parts
.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst
- Oui. Migration entièrement automatisée de la Sous - base de données des tableaux d'effets sous net
Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images
随机推荐
[learning notes] agc010
ESP32系列专栏
Pay close attention to the work of safety production and make every effort to ensure the safety of people's lives and property
【无标题】
通过Keil如何查看MCU的RAM与ROM使用情况
MongoDB的导入导出、备份恢复总结
【黑马早报】华为辟谣“军师”陈春花;恒驰5预售价17.9万元;周杰伦新专辑MV 3小时播放量破亿;法华寺回应万元月薪招人...
How to reset Google browser? Google Chrome restore default settings?
Conversion from non partitioned table to partitioned table and precautions
leecode3. 无重复字符的最长子串
Practical case: using MYCAT to realize read-write separation of MySQL
PCAP学习笔记二:pcap4j源码笔记
Blog recommendation | Apache pulsar cross regional replication scheme selection practice
如何让electorn打开的新窗口在window任务栏上面
JS function 返回多个值
【Presto Profile系列】Timeline使用
AUTOCAD——大于180度的角度标注、CAD直径符号怎么输入?
Scrapy教程经典实战【新概念英语】
centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
DETR介绍