未验证 提交 9af4304f 编写于 作者: C CyC2018 提交者: GitHub

Merge pull request #652 from OOCZC/master

Update SQL.md
...@@ -570,23 +570,23 @@ WHERE col5 = val; ...@@ -570,23 +570,23 @@ WHERE col5 = val;
每次只能给一个变量赋值,不支持集合的操作。 每次只能给一个变量赋值,不支持集合的操作。
```sql ```sql
delimiter // DELIMITER //
create procedure myprocedure( out ret int ) CREATE PROCEDURE myprocedure(OUT ret INT)
begin BEGIN
declare y int; DECLARE y INT;
select sum(col1) SELECT SUM(col1)
from mytable FROM mytable
into y; INTO y;
select y*y into ret; SELECT y*y INTO ret;
end // END //
delimiter ; DELIMITER ;
``` ```
```sql ```sql
call myprocedure(@ret); CALL myprocedure(@ret);
select @ret; SELECT @ret;
``` ```
# 十九、游标 # 十九、游标
...@@ -603,26 +603,27 @@ select @ret; ...@@ -603,26 +603,27 @@ select @ret;
4. 关闭游标; 4. 关闭游标;
```sql ```sql
delimiter // DELIMITER //
create procedure myprocedure(out ret int) CREATE PROCEDURE myprocedure(OUT ret INT)
begin BEGIN
declare done boolean default 0; DECLARE done BOOLEAN DEFAULT 0;
declare mycursor cursor for DECLARE mycursor CURSOR
select col1 from mytable; FOR
SELECT col1 FROM mytable;
# 定义了一个 continue handler,当 sqlstate '02000' 这个条件出现时,会执行 set done = 1 # 定义了一个 continue handler,当 sqlstate '02000' 这个条件出现时,会执行 set done = 1
declare continue handler for sqlstate '02000' set done = 1; DECLARE CONTINUE HANDLER FOR sqlstate '02000' SET done = 1;
open mycursor; OPEN mycursor;
repeat REPEAT
fetch mycursor into ret; FETCH mycursor INTO ret;
select ret; SELECT ret;
until done end repeat; UNTIL done END REPEAT;
close mycursor; CLOSE mycursor;
end // END //
delimiter ; DELIMITER ;
``` ```
# 二十、触发器 # 二十、触发器
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册