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