mysqlストアド・プロシージャ--カーソルの使用は各ロー・レコード(マルチフィールド)を取得します.

944 ワード

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 $

  
転載先:https://www.cnblogs.com/lyhc/p/5760164.html