存储过程IN,OUT,INOUT参数

时间:2021-09-29 11:01:48

Can anyone give me a detailed explanation of the difference between IN, OUT, and INOUT parameters?

任何人都可以详细解释IN,OUT和INOUT参数之间的区别吗?

Thanks.

谢谢。

P.S. I'm using MySQL 5.5

附:我正在使用MySQL 5.5

4 个解决方案

#1


6  

1. IN

1. IN

    mysql> CREATE PROCEDURE in_2(IN value INT )BEGIN SELECT value; SET value =100;SE
    LECT value;END//
    Query OK, 0 rows affected (0.00 sec)

     mysql> SET @s =9//
    Query OK, 0 rows affected (0.00 sec)

    mysql> CALL in_2(@s)//
    +-------+
    | value |
    +-------+
    |     9 |
    +-------+
    1 row in set (0.00 sec)

    +-------+
    | value |
    +-------+
    |   100 |
    +-------+
    1 row in set (0.00 sec)

mysql> SELECT @s;
    -> //
+------+
| @s   |
+------+
|    9 |
+------+
1 row in set (0.00 sec) 

2.OUT

2.OUT

mysql> CREATE PROCEDURE in_3(OUT value INT)
    -> SET value=100//
Query OK, 0 rows affected (0.00 sec)

mysql> SET @x=56//
Query OK, 0 rows affected (0.00 sec)

mysql> CALL in_3(@x)//
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @x//
+------+
| @x   |
+------+
|  100 |
+------+
1 row in set (0.00 sec)

#2


3  

IN parameters are passed in to the SP by value. OUT parameters are returned from the SP by value. INOUT parameters are passed by reference, since they contain one value going in and another coming out.

IN参数按值传递给SP。 OUT参数从SP返回值。 INOUT参数通过引用传递,因为它们包含一个值和另一个值。

#3


0  

Um, in parameters receive data from their caller. out parameters push data to their caller (call-by-reference). inout parameters do both. I'm not sure how to make this more detailed without a clearer idea of what it is you want to know.

嗯,in参数从他们的调用者接收数据。 out参数将数据推送到其调用者(按引用调用)。 inout参数同时执行。如果没有更清楚地了解你想知道什么,我不确定如何更详细。

#4


0  

https://www.youtube.com/watch?v=TCt6IZCZTxc

https://www.youtube.com/watch?v=TCt6IZCZTxc

this video has some good explanation about stored procedures. please go through it

该视频对存储过程有一些很好的解释。请仔细阅读

#1


6  

1. IN

1. IN

    mysql> CREATE PROCEDURE in_2(IN value INT )BEGIN SELECT value; SET value =100;SE
    LECT value;END//
    Query OK, 0 rows affected (0.00 sec)

     mysql> SET @s =9//
    Query OK, 0 rows affected (0.00 sec)

    mysql> CALL in_2(@s)//
    +-------+
    | value |
    +-------+
    |     9 |
    +-------+
    1 row in set (0.00 sec)

    +-------+
    | value |
    +-------+
    |   100 |
    +-------+
    1 row in set (0.00 sec)

mysql> SELECT @s;
    -> //
+------+
| @s   |
+------+
|    9 |
+------+
1 row in set (0.00 sec) 

2.OUT

2.OUT

mysql> CREATE PROCEDURE in_3(OUT value INT)
    -> SET value=100//
Query OK, 0 rows affected (0.00 sec)

mysql> SET @x=56//
Query OK, 0 rows affected (0.00 sec)

mysql> CALL in_3(@x)//
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @x//
+------+
| @x   |
+------+
|  100 |
+------+
1 row in set (0.00 sec)

#2


3  

IN parameters are passed in to the SP by value. OUT parameters are returned from the SP by value. INOUT parameters are passed by reference, since they contain one value going in and another coming out.

IN参数按值传递给SP。 OUT参数从SP返回值。 INOUT参数通过引用传递,因为它们包含一个值和另一个值。

#3


0  

Um, in parameters receive data from their caller. out parameters push data to their caller (call-by-reference). inout parameters do both. I'm not sure how to make this more detailed without a clearer idea of what it is you want to know.

嗯,in参数从他们的调用者接收数据。 out参数将数据推送到其调用者(按引用调用)。 inout参数同时执行。如果没有更清楚地了解你想知道什么,我不确定如何更详细。

#4


0  

https://www.youtube.com/watch?v=TCt6IZCZTxc

https://www.youtube.com/watch?v=TCt6IZCZTxc

this video has some good explanation about stored procedures. please go through it

该视频对存储过程有一些很好的解释。请仔细阅读