开发者

Stored procedures IN, OUT, INOUT parameters

开发者 https://www.devze.com 2023-02-21 18:00 出处:网络
Can anyone give me a detailed explanation of the difference between IN, OUT, and INOUT parameters? Thank开发者_如何学编程s.

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

Thank开发者_如何学编程s.

P.S. I'm using MySQL 5.5


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

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)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消