首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >phpMyAdmin创建MySQL的存储过程

phpMyAdmin创建MySQL的存储过程

作者头像
星哥玩云
发布2022-08-17 20:44:09
发布2022-08-17 20:44:09
1.8K0
举报
文章被收录于专栏:开源部署开源部署

通过phpMyAdmin,创建procedure,用于生成测试数据。

随机的用户名及手机号。

DELIMITER $$ CREATE  PROCEDURE `sp_insert_test_users`(IN `para_count` INT) BEGIN     DECLARE p_username varchar(50);     DECLARE p_countryCallingCode varchar(10) default '86';     DECLARE p_phone varchar(20);     DECLARE p_all_phone varchar(20);     DECLARE p_create_time datetime;        DECLARE p_index int default 0;     DECLARE p_userid int default 0;  IF para_count > 0 THEN     SET p_create_time = NOW();     while p_index < para_count do            select concat(               substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ', rand()*26 , 1),               substring('abcdefghijklmnopqrstuvwxyz', rand()*26 , 1),               substring('abcdefghijklmnopqrstuvwxyz', rand()*26 , 1),               substring('abcdefghijklmnopqrstuvwxyz', rand()*26 , 1),               substring('abcdefghijklmnopqrstuvwxyz', rand()*26 , 1),               substring('abcdefghijklmnopqrstuvwxyz', rand()*26 , 1),               substring('abcdefghijklmnopqrstuvwxyz', rand()*26 , 1),               substring('abcdefghijklmnopqrstuvwxyz', rand()*26 , 1)             ) into p_username;         select concat(               '139',               substring('1234567890', rand()* 10 , 1),               substring('1234567890', rand()* 10 , 1),               substring('1234567890', rand()* 10 , 1),               substring('1234567890', rand()* 10 , 1),               substring('1234567890', rand()* 10 , 1),               substring('1234567890', rand()* 10 , 1),               substring('1234567890', rand()* 10 , 1),               substring('1234567890', rand()* 10 , 1)             ) into p_phone;         if not exists ( select 1 from users where username = p_username or phone = p_phone )         and length(p_username) = 8 and length(p_phone) = 11         then             set p_all_phone = concat(p_countryCallingCode,';',p_phone);             INSERT INTO `users`             (`username`, `countryCallingCode`, `phone`, `_phone`,             `group`,  `created_at`, `updated_at`)             VALUES             (p_username,p_countryCallingCode,p_phone,p_all_phone,             'user', p_create_time, p_create_time);             select @@IDENTITY into p_userid;             INSERT INTO `users_test_mock`             (`userid`,`username`, `countryCallingCode`, `phone`)             VALUES             (p_userid,p_username,p_countryCallingCode,p_phone);             SET p_index = p_index + 1;         end if;     end while; END IF;

END$$ DELIMITER ;

调用:

call sp_insert_test_users(10);

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档