当前位置: 移动技术网 > IT编程>数据库>MSSQL > 生成300个不同的随机数的SQL语句

生成300个不同的随机数的SQL语句

2017年12月12日  | 移动技术网IT编程  | 我要评论

关岭县人民政府网,服务器cpu性能排行,wp8论坛

--生成300个8位不重复纯数字随机数

declare @i int=0;
declare @j int;
declare @qnum int=300; --生成随机数的数量
set nocount on
create table #temp_table(num int)
while(@i<@qnum)
begin
  select @j = cast( floor(rand()*(99999999-10000000)+10000000) as int) 
  if(not exists(select num from #temp_table where num=@j ))
  begin
    insert #temp_table (num) values (@j)
    set @i+=1;
  end 
end
select distinct num from #temp_table
drop table #temp_table

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网