有in类型的参数:
mysql> delimiter //
mysql> create procedure deom_in(in p_in int)
-> begin
-> select p_in;
-> set p_in=3;
-> select p_in;
-> end;
-> //
Query OK, 0 rows affected
mysql> set @p_in=1//
Query OK, 0 rows affected
mysql> call deom_in(@p_in)//
+------+
| p_in |
+------+
| 1 |
+------+
1 row in set
+------+
| p_in |
+------+
| 3 |
+------+
1 row in set
Query OK, 0 rows affected
传入参数未受影响
mysql> select @p_in//
+-------+
| @p_in |
+-------+
| 1 |
+-------+
1 row in set
有out类型的参数:
mysql> create procedure demo_out(out p_out int)
-> begin
-> select p_out;
-> set p_out=3;
-> select p_out;
-> end;
-> //
Query OK, 0 rows affected
mysql> set @p_out=1//
Query OK, 0 rows affected
mysql> call demo_out(@p_out)//
+-------+
| p_out |
+-------+
| NULL |
+-------+
1 row in set
+-------+
| p_out |
+-------+
| 3 |
+-------+
1 row in set
Query OK, 0 rows affected
传入参数被改变
mysql> select @p_out//
+--------+
| @p_out |
+--------+
| 3 |
+--------+
1 row in set
有inout类型的参数:
mysql> create procedure demo_inout(inout p_inout int)
-> begin
-> select p_inout;
-> set p_inout=4;
-> select p_inout;
-> end;
-> //
Query OK, 0 rows affected
mysql> set @p_inout=1//
Query OK, 0 rows affected
mysql> call demo_inout(@p_inout)//
+---------+
| p_inout |
+---------+
| 1 |
+---------+
1 row in set
+---------+
| p_inout |
+---------+
| 4 |
+---------+
1 row in set
Query OK, 0 rows affected
传入参数被改变
mysql> select @p_inout//
+----------+
| @p_inout |
+----------+
| 4 |
+----------+
1 row in set
查看存储过程:
mysql> show procedure status where db='test';//
删除存储过程:
mysql> drop procedure pro//
Query OK, 0 rows affected
注意:在图形化工具的命令模式下,写存储过程不需要delimiter //
他会自动识别。用” ; ”就行了。否则会报错。
If else:
其中:结构
Begin
If ... Then
Elseif ...then
Else ...
End if
End
Case:
While do
repeat···· end repeat:
它在执行操作后检查结果,而while则是执行前进行检查。
相当于do while 先执行再判断
如果输入一个小于7的数: