| Insert 999999 records in table [message #576148] |
Fri, 01 February 2013 00:43  |
mvmkandan
Messages: 66 Registered: May 2010 Location: Trivendrum
|
Member |
|
|
Hi Experts,
I need to insert 999999 records into one table, Already I wrote the below query
DECLARE
TYPE tt_type IS TABLE OF table_name.no%TYPE
INDEX BY BINARY_INTEGER;
tt_type_no tt_type;
rec_count NUMBER;
BEGIN
SELECT LEVEL
BULK COLLECT INTO tt_type_no
FROM DUAL
CONNECT BY LEVEL <= 999999;
FORALL rec_count IN tt_type_no.FIRST .. tt_type_no.LAST
INSERT INTO table_name
(no, checkin_date
)
VALUES (tt_type_no (rec_count), SYSDATE
);
COMMIT;
END;
But It took 5 mins to execute... Is there any other way there to insert fastly.
Thanks
Veera
|
|
|
|
|
|
| Re: Insert 999999 records in table [message #576151 is a reply to message #576150] |
Fri, 01 February 2013 00:50   |
 |
Littlefoot
Messages: 16980 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Less than 4 seconds on my database (Oracle 10g R2, not too powerful machine):
SQL> create table test (id number, datum date);
Table created.
SQL> set timing on
SQL> insert into test (id, datum)
2 select level, sysdate
3 from dual
4 connect by level < 999999;
999998 rows created.
Elapsed: 00:00:03.84
SQL>
[EDIT] Ah, yes - 1 record is missing. My bad.
[Updated on: Fri, 01 February 2013 00:52] Report message to a moderator
|
|
|
|
|
|
| Re: Insert 999999 records in table [message #576157 is a reply to message #576155] |
Fri, 01 February 2013 01:01   |
mvmkandan
Messages: 66 Registered: May 2010 Location: Trivendrum
|
Member |
|
|
Hi,
I forgte to mention one thing.. Already this table has 1,000,000 records.... Now i need to add 999,999 records more. If it is a fresh table then it may be fast. But already it has the records. I can't truncate the table before insert. Because, what the records is stored in the table is important.
Thanks
Veera
|
|
|
|
|
|
|
|
| Re: Insert 999999 records in table [message #576167 is a reply to message #576159] |
Fri, 01 February 2013 02:09  |
Roachcoach
Messages: 1032 Registered: May 2010 Location: UK
|
Senior Member |
|
|
So really what we're saying here is get rid of the pointless PL/SQL 
and so long as we're showing off, my box took 1.71 seconds, though most of that time was spent on the connect by. We need better hamsters
|
|
|
|