sql 数据库循环插入100条记录! 怎么实现? 是不是得用存储过程啊

sql 数据库循环插入100条记录! 怎么实现? 是不是得用存储过程啊,第1张

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

数量多的话用insert

select方法插入,如果只是纯数字的话,可以用系统表

insert

into

tb

(a,b)

select

a.number,b.number

from

master..spt_values

a,master..spt_values

b

where

a.type='p'

and

b.type='p'

and

a.number

between

1

and

100

and

b.number

between

1

and

5


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6767065.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-28
下一篇 2023-03-28

发表评论

登录后才能评论

评论列表(0条)

保存