golang access oracle

1. linux下先装好

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

rpm -ivh oracle-instantclient11.2-basic-12.1.0.2.0.x86_64.rpm
rpm -ivh oracle-instantclient11.2-sqlplus-12.1.0.2.0.x86_64.rpm

export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib

sudo vi /etc/ld.so.conf.d/oracle.conf && sudo chmod o+r /etc/ld.so.conf.d/oracle.conf
/usr/lib/oracle/12.1/client64/lib/

 sudo apt-get install libaio1

sqlplus "scott/xxx@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.11.149)(PORT=1521))(CONNECT_DATA=(SID=orcl)))"

#hostname  结果要在/etc/hosts中有

2. 

sudo ln -s /usr/include/oracle/12.1/client64 $ORACLE_HOME/include
export PKG_CONFIG_PATH=~/pkg_config_path
vi ~/pkg_config_path/oci8.pc

prefix=/usr/lib/oracle/12.1/client64
exec_prefix=${prefix}
libdir=/usr/lib/oracle/12.1/client64/lib
includedir=/usr/include/oracle/12.1/client64

glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums

Name: oci8
Description: oci8 library
Libs: -L${libdir} -lclntsh
Cflags: -I${includedir}
Version: 12.1

oci8.pc view  https://github.com/mattn/go-oci8

go get  github.com/mattn/go-oci8

3. test

https://raw.githubusercontent.com/wendal/go-oci8/master/example/oracle.go

 key:

db, err := sql.Open("oci8", "scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.11.149)(PORT=1521))(CONNECT_DATA=(SID=orcl)))")

    https://help.ubuntu.com/community/Oracle%20Instant%20Client

原文地址:https://www.cnblogs.com/anjuncc/p/5797666.html