------解决方案-------------------- create proc p_rand @rand int output as begin set @rand=convert(int, 100000*rand()) if @rand between 10000 and 99999 and not exists(select 1 from randTable where randNumber = @rand) begin insert into randTable values(@rand) end else set @rand = 0 end
------解决方案--------------------
------解决方案--------------------
SQL code
create proc p_rand
@rand int output
as
begin
--这里开始写内容
declare @a as int=1
WHILE @a=1
BEGIN
SET @rand=convert(int, 100000*rand())
IF NOT EXISTS(SELECT 1 FROM TB WHERE 列=@rand)
BEGIN
INSERT INTO TB(列) SELECT @rand
select @rand --返回随即数.过程没有return语句.直接select就返回了
SET @a=2
END
END
END