Create a MySQL stored procedure and use bitsCN.com
Create and use a MySQL stored procedure
1. create a stored procedure:
SQL code
Create procedure proc_name (out s int) -- CREATE a stored PROCEDURE. proc_name indicates that the out parameter in the stored PROCEDURE name parameter list indicates that the parameter is the return value. The input value is in s. the parameter name int indicates the parameter type.
BEGIN -- starts the stored procedure
SELECT * FROM tbl_name WHERE tbl_id = s; -- this stored procedure indicates querying the result of a tbl_id value of s in the tbl_name table
END; -- END of the stored procedure
2. call the stored procedure
SQL code
SET @ p = 0; -- SET user variables and initialize
CALL proc_name (@ p); -- CALL the CALL command of the stored procedure and put the set variables in the parameter list. note: even if the stored procedure has no variables, write (), this is consistent with the method declaration in the program.
3. View stored procedures
SQL code
SHOW PROCEDURE STATUS
4. delete a stored procedure
SQL code
Drop procedure pro_name -- Stored PROCEDURE name
BitsCN.com