MySQL存储过程详解(6)
4. -> declare x1 varchar(5) default 'outer';
5. -> begin
6. -> declare x1 varchar(5) default 'inner';
7. -> select x1;
8. -> end;
9. -> select x1;
10. -> end;
11. -> //
12.mysql > DELIMITER ;
(2). 条件语句
Ⅰ. if-then -else语句
1. mysql > DELIMITER //
2. mysql > CREATE PROCEDURE proc2(IN parameter int)
3. -> begin
4. -> declare var int;
5. -> set var=parameter+1;
6. -> if var=0 then
7. -> insert into t values(17);
8. -> end if;
9. -> if parameter=0 then
10. -> update t set s1=s1+1;
11. -> else
12. -> update t set s1=s1+2;
13. -> end if;
14. -> end;
15. -> //
16.mysql > DELIMITER ;
Ⅱ. case语句:
1. mysql > DELIMITER //
2. mysql > CREATE PROCEDURE proc3 (in parameter int)
3. -> begin
4. -> declare var int;
5. -> set var=parameter+1;
6. -> case var
7. -> when 0 then
8. -> insert into t values(17);
9. -> when 1 then
10. -> insert into t values(18);
11. -> else
12. -> insert into t values(19);
13. -> end case;
14. -> end;
15. -> //
16.mysql > DELIMITER ;
(3). 循环语句
Ⅰ. while ····end while:
1. mysql > DELIMITER //
2. mysql > CREATE PROCEDURE proc4()
相关新闻>>
- 发表评论
-
- 最新评论 更多>>