如何使用 VBA 连接到 Oracle SQL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12493284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:46:15  来源:igfitidea点击:

How do I connect to Oracle SQL using VBA?

sqloraclevba

提问by Maciej

I'm a newbie with vba, and would appreciate help with connecting to Oracle SQL using VBA. I have such code for MS Server, and need to modify it somehow (or create a new one) so it works with Oracle SQL.

我是 vba 的新手,希望得到使用 VBA 连接到 Oracle SQL 的帮助。我有这样的 MS Server 代码,需要以某种方式修改它(或创建一个新的),以便它与 Oracle SQL 一起使用。

Here's the code:

这是代码:

Public Const sConnect As String = "xxx; Initial Catalog=xxx; User ID=xxx;Password=xxx;"

Sub GetData1()

Sheets(1).Range("a1:ao20000").ClearContents

Dim rsConnection As ADODB.Connection
Dim rsRecordset As ADODB.Recordset
Dim sQuerry As String

sQuerry = "select * from xxx"

Set rsConnection = New ADODB.Connection
Set rsRecordset = New ADODB.Recordset

rsConnection.ConnectionString = sConnect
rsConnection.Open

Set rsRecordset = rsConnection.Execute(sQuerry)

Worksheets(1).Range("A2").CopyFromRecordset rsRecordset

rsConnection.Close

Set rsConnection = Nothing
Set rsRecordset = Nothing

End Sub

My questions are: Do i need to install anything else than Oracle Developer? If so, what? How to change the code to make it work?

我的问题是:除了 Oracle Developer 之外,我还需要安装其他任何东西吗?如果是这样,是什么?如何更改代码以使其工作?

Thanks a lot in advance!! Regards, Maciej

非常感谢提前!问候, Maciej

采纳答案by GTG

You need to install Oracle client software on your computer. The smallest setup is to use Oracle instant client, see http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html.

您需要在您的计算机上安装 Oracle 客户端软件。最小的设置是使用 Oracle 即时客户端,请参阅http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

The only thing you need to change in your program is the connection string

您需要在程序中更改的唯一内容是连接字符串