Some instances understand the mysql database stored procedures and mysql database Stored Procedures
Mysql stored procedure: encapsulate SQL:
Create procedure p1 () beginselect * from t_news; end $ // simple mysql Stored procedure instance
Display stored procedure information: \ G (horizontal table uses vertical table output)
Delimiter $ changes the execution symbol until mysql encounters the $ command to start executing the statement. set names solves the mysql garbled problem, but restores the mysql to the previous Character set status after it is restarted.
Call stored procedure name () call 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 # different from other languages, the then symbol must be added. Note: = Not = select * from t_category where cid> n; elseselect * from t_category where cid <n; end if; end $
Calculate the sum of... n:
Create procedure p4 (n smallint) # include the parameter 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 $
Differences between stored procedure and function: different names: stored procedure: procedure function no return value for Stored procedure
How does mysql use a stored procedure to create the same table for multiple databases?
Two key points:
First, whether your access user has the same permissions for this table. If so, everything is simple.
Second, when you describe a table, you only need to add a database name. Select wc. table. name from wc. table, wcw. table2.name
How to view the execution of stored procedures in the mysql database
Execute the Stored Procedure statement step by step !! View the results of each statement! 1
In this way, we can check whether the execution conditions are correct or not.