Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert 1 million random row into table database Oracle

Tags:

sql

oracle

I can not figure out how to put a huge amount of data in the table. The data must not repeat

Advise, may have other ways?

create table COUNTRIES (
  COUNTRY_ID   VARCHAR2(7),
  COUNTRY_NAME VARCHAR2(40),
  constraint COUNTRY_C_ID_PK primary key (COUNTRY_ID)
);


Begin
For IDS in 1..1000000
Loop
INSERT INTO "SYSTEM"."COUNTRIES" (COUNTRY_ID, COUNTRY_NAME) VALUES (dbms_random.string('L', 7), dbms_random.string('L', 15));
Commit;
End loop;
End; 
like image 731
Yauhen Kavalenka Avatar asked Jul 31 '12 10:07

Yauhen Kavalenka


People also ask

How can I insert multiple rows in a table in Oracle?

The Oracle INSERT ALL statement is used to insert multiple rows with a single INSERT statement. You can insert the rows into one table or multiple tables by using only one SQL command.

How do I add a row to a table in Oracle?

You can add one row at a time to a table with the insert clause. This takes the form: insert into <table_name> ( col1, col2, ... ) values ( 'value1', 'value2', ... )


1 Answers

If you just want the amount of data and do not care about the randomness of the content,

 insert into countries select rownum, 'Name'||rownum from dual
   connect by rownum<=1000000;

should do the trick.

like image 53
Erich Kitzmueller Avatar answered Oct 19 '22 02:10

Erich Kitzmueller