在 Excel VBA 中运行 SQL 查询时出现运行时错误



我正在oracle数据库上运行SQL查询,它只是一个简单的从表中选择*查询。 这适用于 900 行和 5 列的小表。 但是当我在具有 30 列和 95,000 行的表上尝试时,我会收到以下错误。 我尝试增加MaxRecords,但无济于事。

错误 法典

Public Const sConnect As String = "Driver={Microsoft ODBC for
Oracle};Server=server;Uid=user;Pwd=password"
Sub GetData1()
i = 0
Sheets(1).Range("a1:ao20000").ClearContents
Dim rsConnection As ADODB.Connection
Dim rsRecordset As ADODB.Recordset
Dim sQuery As String
sQuery = "select * from trade"
Set rsConnection = New ADODB.Connection
Set rsRecordset = New ADODB.Recordset
rsConnection.ConnectionString = sConnect
rsConnection.Open
rsRecordset.MaxRecords = 1048575
Set rsRecordset = rsConnection.Execute(sQuery)
Worksheets(1).Range("A2").CopyFromRecordset rsRecordset
For i = 0 To rsRecordset.Fields.Count - 1
Worksheets("Sheet1").Cells(1, i + 1).Value = rsRecordset.Fields(i).Name
Next i
rsConnection.Close
Set rsConnection = Nothing
Set rsRecordset = Nothing
End Sub

问候 提姆

经过一番挖掘,我找到了答案。 它与 TIMESTAMP(6( 的数据库字段有关。 我必须重做我的数据库查询才能执行to_char(timestamp_field(,一切都很好。

谢谢 提姆

最新更新