duesentrieb
New Member
- Joined
- Jan 22, 2014
- Messages
- 4
Hi all,
I want to export data (10'000 to 20'000 rows) from Excel to Oracle using VBA. My current solution (see script) uses ADO to read the data cell by cell. ADO batch updates are not really faster than single row updates. What would be significant faster is using a SQL link. However, I appreciate any solution speeding up my script, even the Excel loops. I am seeking ideas like
- is there a way to use some fancy programming technique to speed up the loops (using arrays etc.)
- is there a way to use SQL into Oracle from Excel (like OPENROWSET on SQL Server)
- can I use JET to query the data from excel and export them to Oracle without creating an additional database?
My Script:
Sub myscript()
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Dim conStr As String
Dim rngData As Range, rngHeader As Range
Dim r As Long, c As Long, rMax As Long ' allow more than 32k rows
Dim tStart As Long
conStr = "Provider=OraOLEDB.Oracle.1;Password=somepwd;Persist Security Info=True;User ID=someuser;Data Source=somedatabase"
tStart = Timer
bolStatusBar = Application.DisplayStatusBar
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
con.Open conStr
With rst
.ActiveConnection = con
.Source = "SELECT * FROM targettable"
.CursorType = adOpenKeyset
.LockType = adLockOptimistic 'use with .update
.CursorLocation = adUseServer
.Open
End With
Set rngData = Range("datarange")
Set rngHeader = Range("header")
rMax = rngData.Rows.Count
For r = 1 To rMax 'use rMax also for progress bar
rst.AddNew
For c = 1 To rngData.Columns.Count
rst.Fields(rngHeader(1, c).Value) = rngData(r, c).Value
Next c
rst.Update '12-15 seconds for 1000 records
Next r
con.Close
MsgBox "Done, Time required: " & Int(Timer - tStart) & " seconds."
End Sub
Thank you for any input!
I want to export data (10'000 to 20'000 rows) from Excel to Oracle using VBA. My current solution (see script) uses ADO to read the data cell by cell. ADO batch updates are not really faster than single row updates. What would be significant faster is using a SQL link. However, I appreciate any solution speeding up my script, even the Excel loops. I am seeking ideas like
- is there a way to use some fancy programming technique to speed up the loops (using arrays etc.)
- is there a way to use SQL into Oracle from Excel (like OPENROWSET on SQL Server)
- can I use JET to query the data from excel and export them to Oracle without creating an additional database?
My Script:
Sub myscript()
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Dim conStr As String
Dim rngData As Range, rngHeader As Range
Dim r As Long, c As Long, rMax As Long ' allow more than 32k rows
Dim tStart As Long
conStr = "Provider=OraOLEDB.Oracle.1;Password=somepwd;Persist Security Info=True;User ID=someuser;Data Source=somedatabase"
tStart = Timer
bolStatusBar = Application.DisplayStatusBar
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
con.Open conStr
With rst
.ActiveConnection = con
.Source = "SELECT * FROM targettable"
.CursorType = adOpenKeyset
.LockType = adLockOptimistic 'use with .update
.CursorLocation = adUseServer
.Open
End With
Set rngData = Range("datarange")
Set rngHeader = Range("header")
rMax = rngData.Rows.Count
For r = 1 To rMax 'use rMax also for progress bar
rst.AddNew
For c = 1 To rngData.Columns.Count
rst.Fields(rngHeader(1, c).Value) = rngData(r, c).Value
Next c
rst.Update '12-15 seconds for 1000 records
Next r
con.Close
MsgBox "Done, Time required: " & Int(Timer - tStart) & " seconds."
End Sub
Thank you for any input!