Merge pull request #652 from OOCZC/master

Update SQL.md
This commit is contained in:
CyC2018 2019-04-11 20:33:22 +08:00 committed by GitHub
commit 9af4304fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
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 ;
``` ```
# 二十、触发器 # 二十、触发器