Mysql储存过程2:变量定义与参数传递
时间:2021-07-01 10:21:17
帮助过:27人阅读
declare 变量名 类型 可选类型
-- 跟建表差不多
create procedure p()
begin
declare age
int default(
18);
declare number int default 1;
select age
+number;
end$
/*
mysql> create procedure p()
-> begin
-> declare age int default(18);
-> declare number int default 1;
-> select age+number;
-> end$
Query OK, 0 rows affected (0.00 sec)
mysql> call p$
+------------+
| age+number |
+------------+
| 19 |
+------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
*/
#储存过程 中, 变量可以运算
#运算结果赋修值给变量用: set age :
= 运算式
#set age :
= age
+ 2
#参数传递
mysql> create procedure p2(number int, age int)
-> begin
-> select age+number;
-> end$
Query OK, 0 rows affected (0.00 sec)
mysql> call p2(1,2)$
+------------+
| age+number |
+------------+
| 3 |
+------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
mysql>
Mysql储存过程2:变量定义与参数传递
标签:参数传递 style creat 类型 建表 0 rows bsp 变量 过程