Note/大学笔记/数据库导论/笔记/数据库笔记08——存储——2022.04.11.md
2024-01-12 16:35:29 +08:00

77 lines
953 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 存储过程
## 一、创建存储过程create procedure
### 1.创建无参的存储过程
```mysql
delimiter //
create procedure proc()
begin
select from fruits;
end //
```
```mysql
修改数据库命令结束标志
delimiter //
end //
```
### 2.带输出参数的存储过程
```mysql
delimiter $$
create procedure proc1(out num int)
begin
select count(*)into num from fruits;
end $$
```
### 3.创建带输入输出参数的存储过程
```mysql
delimiter $$
create procedure proc2(in sid int,out n int)
begin
select count(*)into n from fruits where s id=sid;
end$$
```
## 二、调用存储过程call
### 1.调用无参的存储过程
```mysql
call proc();
```
### 2.带输出参数的存储过程
```mysql
call proc(@num);$$
select @num; $$
```
### 3.调用带输入输出参数的存储过程
```mysql
call proc2(101,@n);$$
select @n;$$
```
## 三、删除存储过程
```mysql
drop procedure 存储名
```