设为首页 加入收藏

TOP

phpMyAdmin创建MySQL的存储过程(一)
2019-03-02 00:08:28 】 浏览:253
Tags:phpMyAdmin 创建 MySQL 存储 过程

通过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);
 

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Oracle递归查询start with connec.. 下一篇CentOS Linux 7.5 编译安装 MySQL..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目