This article references the following address:
This article references the following address:
Https://github.com/Centny/Centny/blob/master/Articles/How%20build%20github.com%3amattn%3ago-oci8.md
Golang uses the Thrift framework to perfectly implement cross-language call http://www.linuxidc.com/Linux/2013-09/90748.htm
How to convert a struct pointer to a slice http://www.linuxidc.com/Linux/2013-04/83106.htm in golang
Ubuntu install Go Language Pack http://www.linuxidc.com/Linux/2013-05/85171.htm
Go language programming full HD e-book http://www.linuxidc.com/Linux/2013-05/84709.htm
Go language and beauty-beyond the "Hello World" http://www.linuxidc.com/Linux/2013-05/83697.htm
1. Install Oracle's OCI suite
1. Download the OCI download link (instantclient-basic, instantclient-sdk)
Http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
2. decompress the package to the same directory, for example, instantclient_12_1.
3. root permission to move the folder to/usr/lib
2. Run the following command as root:
# In fact, the same is true for copying directly to cp.
Ln/usr/lib/instantclient_12_1/libclntsh. so.12.1/usr/lib/libclntsh. so
Ln/usr/lib/instantclient_12_1/libocci. so.12.1/usr/lib/libocci. so
Ln/usr/lib/instantclient_12_1/libociei. so/usr/lib/libociei. so
Ln/usr/lib/instantclient_12_1/libnnz12.so/usr/lib/libnnz12.so
# The following two commands are used to run the sqlplus command
Ln/usr/lib/instantclient_12_1/libsqlplusic. so/usr/lib/libsqlplusic. so
Ln/usr/lib/instantclient_12_1/libsqlplus. so/usr/lib/libsqlplus. so
# Add the OCI path to the system's dynamic library loading path and reload it once
Echo/opt/oracle/instantclient>/etc/ld. so. conf
Ldconfig
3. Install pkg-config
4. Create the file oci8.pc in the/usr/lib/pkgconfig directory. The content is as follows:
Prefix =
// Change the path to/usr/lib/instantclient_12_1.
Libdir =$ {prefix}
Includedir =$ {prefix}/sdk/include/
Name: OCI
Description: Oracle database engine
Version: 12.1
// Change the version to the actual version number.
Libs:-L $ {libdir}-lclntsh
Libs. private:
Cflags:-I $ {includedir}
5. If you run step 6 directly, an error indicating that libaio does not exist will be reported. Install the libaio library.
Sudo apt-get install libaio1
6. Install go-oci8
Go get github.com/mattn/go-oci8
7. Add system variables to the. bashrc File
# OCI installation directory
Export ORACLE_HOME =/usr/lib/instantclient_12_1
# Tnsnames. ora file address
Export TNS_ADMIN = $ ORACLE_HOME/network/admin
# Add the OCI installation directory to the dynamic library loading path
Export LD_LIBRARY_PATH = $ ORACLE_HOME
# Oci8.pc file path
Export PKG_CONFIG_PATH =/usr/lib/pkgconfig
8. Content of the tnsnames. ora File
Awsdb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.0.126) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = awsdb)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC1 ))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
For more details, refer to the highlights on the next page.: Http://www.linuxidc.com/Linux/2014-06/102787p2.htm