MySQL存储过程详解(3)
9. mysql > DELIMITER ;
执行结果:
1. mysql > SET @p_out=1;
2. mysql > CALL sp_demo_out_parameter(@p_out);
3. +-------+
4. | p_out |
5. +-------+
6. | NULL |
7. +-------+
8. /*未被定义,返回NULL*/
9. +-------+
10.| p_out |
11.+-------+
12.| 2 |
13.+-------+
14.
15.mysql> SELECT @p_out;
16.+-------+
17.| p_out |
18.+-------+
19.| 2 |
20.+-------+
Ⅲ. INOUT参数例子
创建:
1. mysql > DELIMITER //
2. mysql > CREATE PROCEDURE demo_inout_parameter(INOUT p_inout int)
3. -> BEGIN
4. -> SELECT p_inout;
5. -> SET p_inout=2;
6. -> SELECT p_inout;
7. -> END;
8. -> //
9. mysql > DELIMITER ;
执行结果:
1. mysql > SET @p_inout=1;
2. mysql > CALL demo_inout_parameter(@p_inout) ;
3. +---------+
4. | p_inout |
5. +---------+
6. | 1 |
7. +---------+
8.
9. +---------+
10.| p_inout |
11.+---------+
12.| 2 |
13.+---------+
14.
15.mysql > SELECT @p_inout;
16.+----------+
17.| @p_inout |
18.+----------+
19.| 2 |
20.+----------+
(4). 变量
Ⅰ. 变量定义
DECLARE variable_name [,variable_name...] datatype [DEFAULT value];
其中,datatype为MySQL的数据类型,如:int,float, date, varchar(length)
例如:
1. DECLARE l_int int unsigned default 4000000;
2. DECLARE l_numeric number(8,2) DEFAULT 9.95;
3. DECLARE l_date date DEFAULT '1999-12-31';
4. DECLARE l_datetime datetime DEFAULT '1999-12-31 23:59:59';
5. DECLARE l_varchar varchar(255) DEFAULT 'This will not be padded';
Ⅱ. 变量赋值
SET 变量名= 表达式值[,variable_name = expression ...]
相关新闻>>
- 发表评论
-
- 最新评论 更多>>