Go语言(Golang)中访问Oracle数据库简要环境搭建

陆满庭 · · 1301 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

首先,需要安装第三方数据库驱动包Godror,其中包含了驱动以及支持标准Go语言SQL包规范的函数调用及对象。使用下面的go get方法安装即可。


go get -v github.com/godror/godror


代码中的包导入(即import) 时,要下划线导入gordor包,下划线导入的作用是仅执行其中的init函数,加载驱动。


_ "github.com/godror/godror"


之后编写程序即可编译通过(如何编写代码请参看godror包的说明,在pkg.go.dev查看即可),但如需正确执行访问Oracle数据库的代码,还需要安装oracle客户端。


到下面地址下载,可能需要Oracle的账户,直接注册一个即可。


https://www.oracle.com/database/technologies/instant-client/downloads.html


还需要安装vc运行库,


https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads


这里是最新的vc运行时大全,下载最全的最新的即可。

最后是原文的Oracle客户端安装说明,仅针对Windows下有意义,供大家参考吧。最主要是把下载的客户端的路径加入PATH环境变量中。


Instant Client Installation for Microsoft Windows 64-bit

See the Instant Client Home Page for more information about Instant Client packages.

Client-server version interoperability is detailed in Doc ID 207303.1. For example, Oracle Call Interface 19, 18 and 12.2 can connect to Oracle Database 11.2 or later. Some tools may have other restrictions.

Download the appropriate Instant Client packages for your platform. All installations require the Basic or Basic Light package.

Unzip the packages into a single directory such as C:\oracle\instantclient_19_3

Add this directory to the PATH environment variable. If you have multiple versions of Oracle libraries installed, make sure the new directory occurs first in the path. Restart any terminal windows or otherwise make sure the new PATH is used by your applications.

Download and install the correct Visual Studio Redistributable from Microsoft. Instant Client 19 requires the Visual Studio 2017 redistributable. Instant Client 18 and 12.2 require the Visual Studio 2013 redistributable. Instant Client 12.1 requires the Visual Studio 2010 redistributable.

If you intend to co-locate optional Oracle configuration files such as tnsnames.ora, sqlnet.ora, ldap.ora, or oraaccess.xml with Instant Client, then create a subdirectory such as C:\oracle\instantclient_19_3\network\admin

This is the default Oracle client configuration directory for applications linked with this Instant Client.

Alternatively, Oracle client configuration files can be put in another, accessible directory. Then set the environment variable TNS_ADMIN to that directory name.

Start your application.

ODBC users should follow the ODBC Installation Instructions.


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:陆满庭

查看原文:Go语言(Golang)中访问Oracle数据库简要环境搭建

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1301 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传