Assign value to a variable with set command : Set « Procedure Function « SQL / MySQL






Assign value to a variable with set command

 
mysql>
mysql>
mysql> delimiter $$
mysql> CREATE PROCEDURE myProc()
    -> BEGIN
    ->     DECLARE my_integer     INT;           /* 32-bit integer */
    ->
    ->     set my_integer = 12;
    ->
    ->     select 'my_integer = ' + 12;
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;
mysql>
mysql> call myProc();
+----------------------+
| 'my_integer = ' + 12 |
+----------------------+
|                   12 |
+----------------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>
mysql> drop procedure myProc;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>

        








Related examples in the same category

1.Concatenate string with integer
2.Math operators
3.Using Set to declare variable in a procedure