找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
存储过程题目:现在有一个user用户表,需要往user表中插入1000个登录
用户
要求如下:
1、在插入用户前先判断是否存在1000个登录用户,如果存在则统计表中实
际的行数、如若不存在则自动补齐剩余的数据
2、表名为user,存储过程名字随意取,表中字段有id user_name user_pwd
verify 格式如下(1,user1,123456,W4E38J),且id、用户名不能重复,verify
验证码字段为随机生成6位数验证码
CONCAT函数 可以把2个字符串进行连接

create table cunchu (id int(10) primary key auto_increment,user_name varchar(20),user_pwd int(10),verify varchar(20));
insert into cunchu (id,user_name,user_pwd,verify)values(1,'user1',123456,'e2r321');

drop procedure if exists user_cunchu;
create procedure user_cunchu(n int)
begin
        declare i int(10) default (select count(*) from cunchu);
        declare j varchar(20) default '';
        declare k varchar(20) default '';
        if n<=i then
          select count(*) from cunchu;
        else
          while n>i do
                 set j=(select concat ('user',i+1));
                 set k=(select left (uuid(),6));
                 insert into cunchu(user_name,user_pwd,verify)values(j,123456,k);
                 set i=i+1;
          end while;
                select * from cunchu;
        end if;
       
end

分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册