Bulk insert and record missing [message #613594] |
Thu, 08 May 2014 06:56 |
Malakay79
Messages: 41 Registered: September 2007
|
Member |
|
|
Hi,
I need to insert some records from a table to another.
I use bulk and it's fast but Oracle do not insert last 8000 record.
this is the code
DECLARE
CURSOR nuovi
IS
SELECT di
FROM tab_new;
TYPE nuovi_aat IS TABLE OF tab_new%ROWTYPE
INDEX BY PLS_INTEGER;
l_nuovi nuovi_aat;
BEGIN
OPEN nuovi;
LOOP
FETCH nuovi
BULK COLLECT INTO l_nuovi LIMIT 10000;
EXIT WHEN nuovi%notfound;
FORALL i IN 1 .. l_nuovi.count
-- FOR indx IN nuovi.first .. nuovi.last
INSERT INTO tab /*+ APPEND */
(
...
)
SELECT col1,col2....
FROM user.tables
WHERE col_id IN (l_nuovi(i).id);
COMMIT;
END LOOP;
CLOSE nuovi;
END;
Can anyone tell me why?
|
|
|
|
|
|
|
Re: Bulk insert and record missing [message #613601 is a reply to message #613594] |
Thu, 08 May 2014 07:37 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
As others alrady noticed, plain insert would do. Now about your issue. You misunderstand cursor attribute %notfound. It doesn't mean no more rows were found. It means number of rows requested to fetch was not found. When you do regular single row fetch both statements are same, but you fetch 10000 rows at a time. As a result your code will exit when last fetch fetched from 0 to 9999 rows thus potetially losing that last batch. Change:
EXIT WHEN nuovi%notfound;
to:
EXIT WHEN l_nuovi.count = 0;
SY.
|
|
|
Re: Bulk insert and record missing [message #613604 is a reply to message #613600] |
Thu, 08 May 2014 08:08 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Malakay79 wrote on Thu, 08 May 2014 17:55The classic insert is slower.
Eh? Simple insert should be faster than doing it in PL/SQL. If you say so, then show it. We need proof, just don't say it.
By the way, there are saveral ways to improve it. Such as /*+ append */ hint, which eliminates the undo operation(but only for balance tree indexes). nologging option can also improve the performance since it eliminates the redo operation.
|
|
|