Yesterday we talked about the MySQL tutorial stored procedure creation modification and deletion, this tutorial is about the definition assignment of variables in MySQL stored procedure Oh.
definition of a variable
Define a variable syntax as follows:
declare var_name[,...] Type[default value]
Look at a variable definition instance
declare last date;
Second, theMySQL stored procedure variable assignment
The assignment of a variable can be directly assigned to a query assignment, and direct assignment can be done with set, or it can be a constant or an expression.
set var_name= [, Var_name expr] ...
Assign the last variable to the above method as follows
Set last = Date_sub (Current_date (), interval 1 month);
The following is a query to assign a value to a variable, asking the query to return the result must be a row, the following actions
Select col into var_name[,...] table_expr
We're going to assign a value to V_pay through a query.
Create function Get _cost (P_custid Int,p_eff datetime)
return Decimal (5,2)
Deterministic
Reads SQL data
Begin
DECLARE V_pay decimail (5,2);
Select Ifnull (SUM (pay.amount), 0) into the Vpay from payment where Pay.payd<=p_eff and Pay.custid=pid
REUTRN v_rent + v_over-v_pay;
End $$
OK, this is a simple procedure for defining variables in the stored procedures. The tutorial is here, and we'll go on to define and process the conditions for myql stored procedures .
Note that the original site reproduced the source http://www.111cn.net/database/database.html