mysql通过子查询的方式插入数据


drop procedure if exists test;          
create procedure test()                 
begin
    declare i int;      #申明变量
    declare count int;                      #申明变量
    set i = 0;                          #变量赋值
        set count=(select count(*) from app_device);  #变量赋值
    while i <count do                     #结束循环的条件: 当i大于count时跳出while循环
        INSERT INTO `app_device_contact` (`serial_number`, `tel`) VALUES (
                (select serial_number from app_device order by device_id asc limit i,1), '3');                                                        
        set i = i + 1;                  #循环一次,i加一
    end while;           
        select * from app_device_contact;                   #查看test表数据
end
call test();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM