Link to home
Start Free TrialLog in
Avatar of Thirupathi Lagishetti
Thirupathi Lagishetti

asked on

VB Code to fetch data from oracle more than 65K records, either in single sheet or multiple sheet

Hi
I have a requirement in VB script to fetch data from oracle and copy nearly 100K records in excel sheet,
so far i was able to write this code to fetch 65K records, but not able to fetch 100k records in excel sheet.

Sub ConnectTOOracle()
 
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim mtxData As Variant
    
    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    
    cn.Open ( _
    "User ID=userhr" & _
    ";Password=passwdhr" & _
    ";Data Source=HR_TEST" & _
    ";Provider=OraOLEDB.Oracle")
    
    rs.CursorType = adOpenForwardOnly
 rs.Open ("SELECT LEVEL level_a,  COL1,  1 COL2,  2 COL3,2 COL4,2 COL5 FROM   ( SELECT 1 COL1 FROM dual   UNION ALL   SELECT 3  FROM dual  )  CONNECT BY LEVEL <= 16"), cn
    
    mtxData = Application.Transpose(rs.GetRows)
    
    Sheets("Sheet222").Activate
    
   Range("A2").Resize(UBound(mtxData, 1) - LBound(mtxData, 1) + 1, UBound(mtxData, 2) - LBound(mtxData, 2) + 1) = mtxData

    'Cleanup in the end
    Set rs = Nothing
    Set cn = Nothing
  
End Sub

Open in new window


any help will be appreciated.

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Thirupathi Lagishetti
Thirupathi Lagishetti

ASKER

Thanks you very much <Rgonzo1971>, it is solved my problem, cheers !!!