简单的MySql游标创建
时间:2021-07-01 10:21:17
帮助过:23人阅读
DROP PROCEDURE IF exists StatisticStore1;
2 CREATE PROCEDURE StatisticStore1()
3 BEGIN
4 DECLARE c_name
VARCHAR(
50);
5 DECLARE c_id
INT(
6);
-- 声明结束标志
6 DECLARE i
int default 1;
7 DECLARE b
int default 0;
8 DECLARE cur
CURSOR for SELECT name,id
FROM tb_sort;
9 DECLARE CONTINUE HANDLER
FOR NOT FOUND
SET b
= 1;
10 -- 开启游标
11 OPEN cur;
12
13 FETCH cur
INTO c_name,c_id;
14 while b
<>1 do
15 INSERT INTO tb_books (NAME,author,buytime,sort_id)
VALUES (concat(c_name,
‘下的图书‘,i),
‘ACCP‘,now(),c_id);
16 FETCH cur
INTO c_name,c_id;
17 END while;
18 -- 关闭游标
19 CLOSE cur;
20 END;
21
22 call StatisticStore1();
简单的MySql游标创建
标签:values cat har concat span auth 游标 exist bsp