Stored Proceduresparameter: In the parentheses of the stored procedure, you can declare the parameters. The syntax is CREATE PROCEDURE P ([in/out/inout] Parameter Name argument type:)In: The parameter is passed to the value, the defined parameter gets the value out: The parameter of the schema definition can only be assigned within the procedure body, indicating that the parameter may pass a value callback with his procedure (inside the stored procedure,the initial value of this parameter is NULL, regardless of whether the caller sets a value for the stored procedure parameterInOutcallers can also pass values to the stored procedure through the InOut parameter, or they can pass values from inside the stored procedure to the caller
If you just want to pass the data to the MySQL stored procedure, use the "in" type parameter, and if you only return the value from the MySQL stored procedure, use the "out" type parameter, and if you need to pass the data to the MySQL stored procedure, and then pass it back to us after some calculation, we use " InOut "type parameter.
- DELIMITER $$
- CREATE PROCEDURE p1 (innum INT)
- BEGIN
- DECLARE i INT DEFAULT 0;
- DECLARE Total INT DEFAULT 0;
- While I<=num do
- SET Total: = i + all;
- SET I: = i+1;
- END while;
- SELECT Total;
- end$$
Stored procedure pass-through argument out
[SQL]View Plain copy
- CREATE PROCEDURE p2 (outnum INT)
- BEGIN
- SELECT num as num_1;
- IF (num is isn't NULL) Then
- SET num = num + 1;
- SELECT num as num_2;
- ELSE
- SELECT 1 into num;
- END IF;
- SELECT num as num_3;
- end$$
- SET @num = 10$$
- Call P2 (@num) $$
- SELECT @num as num_out$$
- CREATE PROCEDURE P3 (INOUT age INT)
- BEGIN
- SET Age: = age + 20;
- end$$
- Set @currage =18$$
- Call P3 (@currage) $$
- Select @currage $$
MySQL stored procedure Pass in, out, inout parameter usage