Append to Oracle too slow

I am using an Access database front end to an Oracle back end. I create a temporary table for data within MS Access and then want to append that data to the Oracle table. The code I am currently using works, but take 6 minutes to append only 800 records! If anyone has any ideas on speeding this up, I'd sure be interested. I'm also analyzing and computing statistics on the Oracle side just about every time I do something just to try and help the speed.

I have set up two test tables to get this functioning before I go with live data. The table in Oracle is called JSHL_WO_LD_TEST. The table in Access is called jsht_LONG_DESCRIPTION. I'm not a programmer so please forgive my naming conventions. I'm using the following code to append from Access to Oracle:

Sub append_ld_to_oracle()

DoCmd.SetWarnings False

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("jsht_LONG_DESCRIPTION")


While Not rs.EOF
  CurrentDb.Execute "INSERT INTO JSHL_WO_LD_TEST _
     ('" & Replace(rs(0), "'", "''") & "', '" & Replace(rs(1), "'", "''") _
     & "', '" & Replace(rs(2), "'", "''") & "', '" & Replace(rs(3), "'", "''") & "');"

DoCmd.SetWarnings True

End Sub
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Steve BinkConnect With a Mentor Commented:
I apologize for the delay in getting to this question.  These hurricanes are being rather inconsiderate in not checking my schedule....I'll have to talk to their manager...

In any case, I gather from your posts here that you solved the last ADO problem you were having from the previous question?

Triggers are a form of automation.  An easy example would be for a library check-out system.  If someone has a late book, their account is marked with a block until they pay the fine.  To automate removing the block, you could put a trigger on the Payments table to check the sum of fines still due.  This way, every time a payment is made, the trigger would run, check to see if all fines have been paid, and, if necessary, automatically update the table to reflect removal of the block.  rockmuncher's post regarding triggers is a valid point.  If you have any triggers operating on the Oracle side of your connection, they will likely slow down the INSERT considerably.

Another suggestion handled in our previous question involves looping through the recordset.  Going through a local recordset and conducting the INSERT record-by-record will always take longer than doing it all at once through SQL.  The best performance you can expect is if you link the Oracle table in Access, and do the INSERT on the Access side through that linked table.  I have to agree with rockmuncher again, will likely not see any significant boost in performance.  At this point, I believe your execution time is a result of the communication overhead between Access and Oracle.

Importing a text could be another way around this issue for you.  You can set up a routine to export the data to a file, copy the file to the Oracle server, then import it locally on Oracle.  With 800+ records, including a memo field, you could potentially see MUCH better performance using this route.  Not being familiar with Oracle, I would recommend you start a question for this item in the Oracle TA with a pointer here for the back story.
joelhoffmanAuthor Commented:
Oh, and here is the structure of these very simple tables:

----------------------------------------- -------- -----
WONUM                                          CHAR(12)
LDKEY                                             CHAR(40)
REPORTDATE                                  DATE
LDTEXT                                          LONG
2 records per second using discreet INSERT statements is not unreasonable for ACCESS -> ORACLE, even for simple structures.  

On the ORACLE side of things you can often find that triggers will slow down inserts, and can be disabled for the duration of a batch insert if you are CERTAIN that you can accomplish what they are meant to do in data (eg. get the next sequence number for the primary key, adjust data in another table, etc.  Make sure you update any sequences if you bypass them, and turn triggers back on!

On the Access side of things you might be able to increase speed by using Docmd.Transferdatabase instead of looping through a recordset.  Obviously you would have to perform all of the data conversions (ie. replace single quote with 2 x single quote) first, or in ORACLE after completion

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

rockmuncherConnect With a Mentor Commented:
Alternatively you could just run an append query that does the lot in one go (eliminating the recordset from your original example)

eg.   CurrentDb.Execute "INSERT INTO JSHL_WO_LD_TEST
Again, you would have to perform all of the data conversions (ie. replace single quote with 2 x single quote) first, or in ORACLE after completion, or you could adjust the query adding the replace statements back in.
joelhoffmanAuthor Commented:

I initially started with the Access Append command but it was horribly slow. So I came in here and saw where someone suggested doing it the "recordset" way and so I tried that. I'm in training this week so will try your suggestions early next week. Thanks for the help!
joelhoffmanAuthor Commented:
ok, here's what I just tried and it took 5 minutes to load only 831 records with only 4 fields:

Sub append_ld_to_oracle()


End Sub

I don't know how to do what has been suggested about "triggers". Maybe someone could explain that? Or maybe I should try the transferdatabase command mentioned above?


joelhoffmanAuthor Commented:
Is there a way I could import a text file on my PC directly into my Oracle tables using SQL Plus? Maybe that would be faster rather than using MS Access?
joelhoffmanAuthor Commented:
I'm awarding points on another thread and moving that thread's conversation here since it has turned into one more relative to my question here. The other thread's location:

joelhoffmanAuthor Commented:

Nope, I didn't solve the ADO question. I'm reposting it below. Thanks for your diligence in following me over to this thread. I'll post my text import question over in the Oracle area. Since our DBA only set this test up for me to work with I don't think there would be any triggers on the Oracle side. I'm the only person fooling with the database at the moment.

Here's my current code attempting to use ADO (error below):

Dim Cnxn As ADODB.Connection
    Dim cmdChange As ADODB.Command
    Dim strSQL As String
    ' Define SQL statement to execute as command text
    strSQL = "INSERT INTO rrcfat.WO_LD_TEST_TBL (WONUM, LDKEY, REPORTDATE, LDTEXT) SELECT * from jsh_long_desc;"
    ' Open a connection using a DSN and individual
    ' arguments instead of a connection string.
    Set Cnxn = New ADODB.Connection
    Cnxn.ConnectionTimeout = 30
    Cnxn.Open "oxyt", "rrcfat", "rrcfat"
    ' See if I opened the connection
    MsgBox "cnxn state: " & Cnxn.State
     ' Create and execute command object
    Set cmdChange = New ADODB.Command
    Set cmdChange.ActiveConnection = Cnxn
    cmdChange.CommandText = strSQL

    ' Close the connection

    ' See if I closed the connection
    MsgBox "cnxn state: " & Cnxn.State


When I run the above, I get an error:

Run-time error '-2147217865 (80040e37)':

[Oracle][ODBC][Ora]ORA-00942: table or view does not exist

Remember: the table "jsh_long_desc" is a local MS Access table. Will the SQL going through ADO be able to correctly reference my local Access table to insert from?
Steve BinkCommented:
No, you would have to set up a linked table on one side or the other, and use that side to run the INSERT.  For example, if you create the link in Access, it would then consider table [rrcfat] as a local Access table for the purpose of your query.  You could then remove the ADO connection from the sub and use DAO.  Access would handle the connection to Oracle from there, though most likely it would ODBC (speed issue again..).  You could also try it the other way (creating a link table in Oracle) and use the existing code you have now.  In that scenario, you would be using ADO to connect to Oracle, which would probably use ODBC to implement the link back to Access.

You also have the use if the IN clause for SQL, but Microsoft recommends using a linked table instead due to performance issues.
joelhoffmanAuthor Commented:
Just so anyone reading this thread knows, my DBA had these tables set up on what he called a "test instance". He moved my tables over to the "Production" instance and thought I would see a speed gain by doing so. Unfortunately, it still took 5 minutes to load only 800 records. I'm going to close this thread and award the points then move the discussion over to the Oracle area. Thanks for the comments!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.