user1971598
user1971598

Reputation:

Insert into table using result set of dual query?

I have a table, edgar_t100 and which is a table of one column, named ID. I need it to have 100 rows where each row/column intersection is just the number of the row. Obviously I don't want to do this by writing insert clauses, so I thought about using the dual table from Oracle.

If I do, select rownum as ID from dual connect by rownum <= 100, then I get a nice table that captures exactly what I want.

Is there a way to do something like the following:

insert into edgar_t100 values (select rownum as ID from dual connect by rownum <= 100) (Obviously that doesn't work and I want to do this using SQL)

Upvotes: 1

Views: 3333

Answers (1)

Robert
Robert

Reputation: 25753

Try this way:

insert into edgar_t100 (col1) 
select rownum as ID 
from dual 
connect by rownum <= 100

Upvotes: 3

Related Questions