MySQL stored procedures:encapsulating SQL :
CREATE PROCEDURE P1 () beginselect * from T_news;end $ //mysql stored procedure Simple instance
Display Stored procedure information: \g (horizontal table with vertical table output)
Delimiter $ change execution symbol until MySQL encounters $ start Execution statement command set names fix mysql garbled problem but MySQL restarts and reverts to the previous character set state
Call stored procedure name () calls stored procedure
Parameters:
CREATE PROCEDURE p2 (n int) #含参beginselect * from t_category where CID > N;end $
Control structure:
CREATE PROCEDURE p3 (n int, J char (1)) #含参begin if j= ' h ' then #与其他语言不同 must be added then note symbol = not = = Select * fro M t_category where cid > N;elseselect * from t_category where CID <n; End If;end $
Computes the and of 1....N: &NBSP;&NBSP;
CREATE PROCEDURE P4 (n smallint) #含参begin Declare i int;declare s int;set s = 0;set i = 1;while i<=n doset s =s+i;set i=i+1;end while;select S;end $
The difference between stored procedures and functions: Name differs: Stored procedure: Procedure function stored procedure does not return a value