存储过程-mysql

-- 如果存在则删除这个对象
drop procedure if exists p_insert_data;
-- 创建一个存储过程,名字是p_insert_data
create procedure p_insert_data()
begin
    -- 定义变量
    declare _name varchar(20);
    declare _phone varchar(11);
    declare _score int(11);
    -- 1:定义一个整型初始变量,名称是_flag
    declare _flag int(11);
    -- 2:赋予一个初始值为0
    set _flag = 1;
    -- 3:当_flag小于等于100时,重复去插入
    while _flag <=100000 do
            -- 名称的形式是:switchon-_flag   switchon-1   switchon-2
            set _name = CONCAT('switchon',_flag); con
            set _phone = 13000000000 + _flag;
            set _score = rand()*100;
            -- 插入一条数据
            insert into score(sname,phone,score) values(_name,_phone,_score);
            -- 循环的迭代语句,让循环在适当时候结束,避免死循环
            set _flag = _flag + 1;
    end while;
end
 
 
posted @ 2025-02-13 11:17  依羽杉  阅读(9)  评论(0)    收藏  举报