gpt4 book ai didi

用于随机填充行的MySql过程仅填充一行

转载 作者:行者123 更新时间:2023-11-30 00:35:14 26 4
gpt4 key购买 nike

我有一个随机填充表中记录的过程。但是当我执行该过程时,该过程仅插入一行。谁能帮忙!

create procedure aa 

( @row INT
)

as
begin
declare @numint as int
declare @string as VARCHAR(10)
declare @length as INT
declare @code as INT
declare @oid as uniqueidentifier

set @numint =0;

WHILE @numint <= @row

BEGIN
SET @numint = @numint + 1;

set @oid = newid();

SET @length = ROUND(10*RAND(),0);

SET @string = '';

WHILE @length > 0 BEGIN

SET @length = @length-1;

SET @code = ROUND(10*RAND(),0) - 1;

IF @code BETWEEN 1 AND 26
SET @string = @string + CHAR(ASCII('a')+@code-1);
ELSE
SET @string = @string + ' ';
END
end
-- Ready for the record

SET NOCOUNT ON;

INSERT INTO test_table VALUES (

@oid,

@numint,

ROUND(2000000*RAND()-1000000,2),

CONVERT(DATETIME, ROUND(50000*RAND()-10000,2)),

@string

)
END

exec procedure '10'

最佳答案

您的插入语句位于循环之外。将其向上移动到第一个循环内,您应该获得正确的行数。

关于用于随机填充行的MySql过程仅填充一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22236504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com