Today, the MySQL stored procedures to learn, we first look at the following code:
A friend who doesn't understand grammar can look at the grammatical structure in detail.
The code is as follows |
Copy Code |
Create PROCEDURE and create FUNCTION Syntax CREATE [definer = {User | Current_User}] PROCEDURE sp_name ([proc_parameter[,...]]) [Characteristic ...] Routine_body CREATE [definer = {User | Current_User}] FUNCTION sp_name ([func_parameter[,...]]) RETURNS type [Characteristic ...] Routine_body Proc_parameter: [In | Out | INOUT] Param_name Type Func_parameter: Param_name type Type Any valid MySQL data type Characteristic: COMMENT ' String ' | LANGUAGE SQL | [NOT] Deterministic | {CONTAINS SQL | NO SQL | Reads SQL DATA | Modifies SQL DATA} | SQL Security {Definer | Invoker} Routine_body: Valid SQL Routine statement |
Cases
The code is as follows |
Copy Code |
DELIMITER $$/* Change the statement terminator * * Use ' Test ' $$/* Select Database * * Drop PROCEDURE if EXISTS ' Outgo ' $$/* exists Outgo stored procedure to delete * * CREATE definer= ' root ' @ '% ' PROCEDURE ' Outgo ' (in V_table CHAR (Ten), in v_id INT (2), out V_value VARCHAR (32)) |
The syntax for calling a stored procedure is call.
code is as follows |
copy code |
mysql> call Outgo (' user ', 2, @a); +----+--------------+ | id | title&n bsp; | +----+--------------+ | 2 | Your big Uncle | +----+--------------+ 1 row in Set (0.00 SEC) Query OK, 0 rows Affected (0.00 sec) mysql> call Outgo (' user ', 1, @a); +----+--------------------+ | id | title | +----+--------------------+ | 1 | I'll test it. | +----+------------- -------+ 1 row in Set (0.00 sec) |
The