存储过程导数据

CREATE DEFINER=`hd_rds_admin`@`%` PROCEDURE `my_proc`()

BEGIN

  DECLARE _nowTime DATE;

    DECLARE _account VARCHAR(255);

    DECLARE _password VARCHAR(255);

      DECLARE _realname VARCHAR(255);

      DECLARE _cellphone VARCHAR(255);

      DECLARE stop_flag TINYINT;



      DECLARE done INT DEFAULT FALSE;   

      DECLARE cur CURSOR FOR  select  account,password,realname,cellphone from vzy2014.purchase_user where role in (1,3) and level=2 and status=1;



      DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;



    SET _nowTime = NOW();

    SET stop_flag = 0;


    OPEN cur;





    read_loop: LOOP


            FETCH  NEXT from cur INTO _account, _password,_realname,_cellphone;

            IF done THEN

                LEAVE read_loop;

            END IF;

    INSERT INTO `book_sort_user`(account,password,`realname` ,`cellphone` ,`create_time` ) VALUES ( _account, _password,_realname,_cellphone, _nowTime);

    END LOOP;

END

你可能感兴趣的:(存储过程导数据)