如何在Go中连接到Oracle

问题描述:

I gather there are two ways to connect to Oracle DB in Go (on windows):

  1. github.com/tgulacsi/goracle
  2. github.com/mattn/go-oci8

But for someone of my level (beginner in open source+golang), those two methods/drivers are awfully tricky.

It's also a burden having to go through all of that for deployment, development on different machines etc. (Also assuming it will work).

Is there a better way to connect to Oracle db in golang or if there is not then can someone explain to me in high level view or any view for that matter that would make this easier?

Pointers would be very much appreciated.

TQ.

我收集到有两种方法可以在Go中(在Windows上)连接到Oracle DB: p>

  1. github.com/tgulacsi/goracle LI>
  2. github.com/mattn/go-oci8 LI> 醇> 但是对于我这个级别的人(开源+ golang的初学者)来说,这两种方法/驱动程序都非常棘手。 p>

    这也是部署所有方法的负担 ,在不同的机器上进行开发等。 p>

    是否有更好的方法可以在golang中连接到Oracle数据库,或者如果没有,那么有人可以在高层视图或任何与此相关的视图中向我解释,这将使此操作变得容易吗? p>

    非常感谢您使用指针。 p>

    TQ。 p> div>

If you are still interested, I have been working with Go and Oracle on Windows for a few months now. My favorite driver so far is go-oci8. It is much faster than goracle and seems to be more active.

Some of our applications need to be deployed on computers that we don't have access to. Both native SQL drivers are compiled with the application without the need for any external configuration, so that is a huge plus. The computer will still need Oracle client installed, but that is the only external dependency.

I won't say go-oci8 is production ready yet, but it's stable enough when you know its limitations. One example is that it panics when running on multiple goroutines simultaneously, so if you need that you might want to use a mutex.

I have basically followed this tutorial to install it: https://gist.github.com/mnadel/8678269

The trickiest part was creating oci8.pc corretly. Mine is:

prefix=/devel/target/1.0
exec_prefix=${prefix}
libdir=C:/oracle/instantclient_12_1_64/sdk/lib/msvc
includedir=C:/oracle/instantclient_12_1_64/sdk/include
oralib=C:/oracle/instantclient_12_1_64/sdk/lib/msvc
orainclude=C:/oracle/instantclient_12_1_64/sdk/include
gcclib=c:/MinGW_64/mingw64/lib
gccinclude=c:/MinGW_64/mingw64/lib
glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums
Name: oci8
Version: 12.1
Description: oci8 library
Libs: -L${oralib} -L${gcclib} -loci
Libs.private:
Cflags: -I${orainclude} -I${gccinclude}

Some things might be reduntant, I might try to improve it on a clean machine.

An important thing to have in mind is that you should use the same architecture for Go and the Oracle client. So if you want to use the 64 bit version of Go you will also need the 64 bit version of Oracle. I have both 32 and 64 bit versions of both, and while 64 bit is my default I use bat files to change the necessary paths and environment variables when I need to build a 32 bit version.

It might be worth investing some time to make it work, you will probably get much better performance than using ODBC. I have been using it with somewhat high data volume (queries that fetch 5+ million rows) and it works very well.