当前位置:网站首页>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;
边栏推荐
- . Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
- Differences between MySQL storage engine MyISAM and InnoDB
- How to continue after handling chain interruption / sub chain error removed from scheduling
- MongoDB命令汇总
- 简单好用的代码规范
- User management summary of mongodb
- ESP32系列专栏
- 初学XML
- 数字ic设计——SPI
- 【学习笔记】AGC010
猜你喜欢
随机推荐
About how appium closes apps (resolved)
【无标题】
分布式事务解决方案
[learning notes] zkw segment tree
Practical example of propeller easydl: automatic scratch recognition of industrial parts
API query interface for free mobile phone number ownership
error LNK2019: 无法解析的外部符号
Why can basic data types call methods in JS
Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
[learning notes] agc010
DrawerLayout禁止侧滑显示
RecyclerView的数据刷新
cmake 学习使用笔记(一)
[untitled]
Unity 构建错误:当前上下文中不存在名称“EditorUtility”
PCAP学习笔记二:pcap4j源码笔记
解决缓存击穿问题
Realbasicvsr test pictures and videos
Pcap learning notes II: pcap4j source code Notes
事务的七种传播行为