
MySQL进阶-存储过程

1.基本语法
1 | DELIMITER $$ -- 修改SQL语句的结束符为$$ |
2.变量
- 系统变量
1
2
3show session/global variables --支持模糊查询
select @@autocommit --查看变量
set @@autocommit = 0 --修改变量 - 自定义变量
1
2
3-- 仅限会话
set @变量名 = 值
select @变量名 -- 查看 - 局部变量
1
2
3-- 仅限存储过程
declare 变量名 '类型' [default 值]
set 变量名 = 值
3.流程控制
- if
1
2
3
4
5-- 单分支
if 条件 then
elseif then
else
end if; - 参数
1
2-- 参数
IN 输入参数 OUT 输出参数 INOUT 输入输出参数 - 循环:
- while
- repeat 满足条件退出循环
- loop 配合 leave 退出循环 iterate 继续下次循环 使用
1
2
3
4while 条件 do
end while;
repeat
until 条件 end repeat;
4.游标
1 | -- 游标 |
5.异常
1 | -- 异常 |
- Title: MySQL进阶-存储过程
- Author: Jason
- Created at : 2023-09-07 21:16:38
- Updated at : 2023-09-10 16:00:44
- Link: https://xxxijason1201.github.io/2023/09/07/MySQL/存储过程/
- License: This work is licensed under CC BY-NC-SA 4.0.
Comments