variable definitions in the #储存过程DeclareVariable name type Optional type--It's like building a watch .Create procedurep ()begin DeclareAgeint default( -); Declare Number int default 1; SelectAge+ 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 |+------------+| |+------------+1 Row in Set (0.00 sec) Query OK, 0 rows affected (0.01 sec)*/in #储存过程, variables can be assigned to variables using the result of the # operation:SetAge:=Expression #SetAge:=Age+ 2
#参数传递mysql> Create procedureP2 ( Number int, ageint) - begin - SelectAge+ Number; - End$Query OK,0Rows Affected (0.00sec) MySQL>Call P2 (1,2)$+------------+|Age+ Number |+------------+| 3 |+------------+1Rowinch Set(0.00sec) Query OK,0Rows Affected (0.01sec) MySQL>
MySQL Storage procedure 2: variable definition and parameter passing