如何连接到Oracle数据库?

I am using Fedora 23 and installed Oracle 12.1 and Go 1.7.1

When I run:

go get github.com/mattn/go-oci8

I am getting an error:

/usr/bin/ld: skipping incompatible /usr/lib/oracle/12.1/client64/lib/libclntsh.so when searching for -lclntsh

/usr/bin/ld: cannot find -lclntsh

collect2: error: execution of ld completed with return code 1

What did you put in your oci8.pc file?

I've just got this working with the below. Keeping in mind I have only the oracle 11.2 instant client installed under the prefix path. I assume you would have to change the version number to the appropriate number.

prefix=/home/sbr/wk/apps/oracle/product/11.2.0/client_1
exec_prefix=${prefix}
libdir=${prefix}
includedir=${prefix}/sdk/include

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: 11.2

1、install goracle

2、install TMD GCC.

3、use sql.open to connect to Oracle.here is a little Example.

package main

import (
    "fmt"
    "database/sql"
    _ "gopkg.in/goracle.v2"
)

func main(){

    db, err := sql.Open("goracle", "scott/tiger@10.0.1.127:1521/orclpdb1")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer db.Close()


    rows,err := db.Query("select sysdate from dual")
    if err != nil {
        fmt.Println("Error running query")
        fmt.Println(err)
        return
    }
    defer rows.Close()

    var thedate string
    for rows.Next() {

        rows.Scan(&thedate)
    }
    fmt.Printf("The date is: %s
", thedate)
}

from oracle blog