Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

sql - How to insert 100 rows in a table?

I have a table ENJOY(id int not_null auto_increment,name char(30)) I have to insert 100 rows with 3 values of name (cn,pogo,disney) with the count of ids increasing


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like you're looking for some kind of a row generator. If that's so, see whether this helps.

Note line #9: I'm inserting 3 rows of each name (to make the result simpler and easier to read); you'd insert 100 rows.

SQL> create table enjoy (id int, name varchar2(10));

Table created.

SQL> insert into enjoy (id, name)
  2  with names as
  3    (select 'cn' name from dual union all
  4     select 'pogo'    from dual union all
  5     select 'disney'  from dual
  6    )
  7  select column_value, name
  8  from names cross join table(cast(multiset(select level from dual
  9                                            connect by level <= 3
 10                                           ) as sys.odcinumberlist));

9 rows created.

SQL> select * from enjoy;

        ID NAME
---------- ----------
         1 cn
         2 cn
         3 cn
         1 pogo
         2 pogo
         3 pogo
         1 disney
         2 disney
         3 disney

9 rows selected.

SQL>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...