1、创建测试表,
create table test_loop(id varchar2(20),remark varchar2(20))
2、循环插入测试数据;
begin
for i in 1..100 loop
insert into test_loop
values(i,'level_'||i)
end loop
commit
end
3、查询表中全量数据;select t.*, rowid from test_loop t
4、编写语句,查询表中记录数,可以看到结果为100;
select count(*) sec from test_loop t
老师不是说的很清楚吗?用函数!CREATE FUNCTION dbo.f_str(@id int)
RETURNS varchar(8000)
AS
DECLARE @i int
DECLARE @name varchar(10) --姓名
DECLARE @villageCode varchar(20) --所属村代码
Set @i = 0
--开始循环插入数据:
WHILE @i <3000
BEGIN
Set @i =@i +1
SET @name = (select top 1 Name from ConstructionPlatformDB.dbo.BasePerson ORDER BY NEWID()) --随机取数据
set @villageCode = (select top 1 Code from Countrywide where len(code) = 12 ORDER BY NEWID())
insert into Operators(Name,VillageCode) values(@name,@villageCode)
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)