mysql 游标用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
delimiter $
create  PROCEDURE  phoneDeal()
BEGIN
     DECLARE   id  varchar (64);    -- id
     DECLARE   phone1   varchar (16);  -- phone
     DECLARE   password1   varchar (32);  -- 密码
     DECLARE   name1  varchar (64);    -- id
     -- 遍历数据结束标志
     DECLARE  done  INT  DEFAULT  FALSE ;
     -- 游标
     DECLARE  cur_account  CURSOR  FOR  select  phone, password , name  from  account_temp;
     -- 将结束标志绑定到游标
     DECLARE  CONTINUE  HANDLER  FOR  NOT  FOUND  SET  done =  TRUE ;
    
     -- 打开游标
     OPEN   cur_account;     
     -- 遍历
     read_loop: LOOP
             -- 取值 取多个字段
             FETCH   NEXT  from  cur_account  INTO  phone1,password1,name1;
             IF done  THEN
                 LEAVE read_loop;
              END  IF;
 
         -- 你自己想做的操作
         insert  into  account(id,phone, password , name ) value(UUID(),phone1,password1,CONCAT(name1, '的家长' ));
     END  LOOP;
 
 
     CLOSE  cur_account;
END  $

  

猜你喜欢

转载自blog.csdn.net/wrh_csdn/article/details/80112059
今日推荐