Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stored procedures IN, OUT, INOUT parameters

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

Thanks.

P.S. I'm using MySQL 5.5

like image 374
xdevel2000 Avatar asked Apr 04 '11 11:04

xdevel2000


3 Answers

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.

like image 93
Elad Lachmi Avatar answered Nov 13 '22 04:11

Elad Lachmi


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)
like image 7
zloctb Avatar answered Nov 13 '22 05:11

zloctb


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.

like image 1
bmargulies Avatar answered Nov 13 '22 05:11

bmargulies