英文:
How can I connect to Oracle database?
问题
我正在使用 Fedora 23,并安装了 Oracle 12.1
和 Go 1.7.1
。
当我运行:
go get github.com/mattn/go-oci8
我遇到了一个错误:
>/usr/bin/ld: 在搜索 -lclntsh 时跳过不兼容的 /usr/lib/oracle/12.1/client64/lib/libclntsh.so
>
> /usr/bin/ld: 找不到 -lclntsh
>
> collect2: 错误:ld 的执行返回代码为 1
英文:
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
答案1
得分: 1
你在oci8.pc文件中放了什么内容?
我刚刚使用以下内容使其正常工作。请记住,我只安装了oracle 11.2的即时客户端,并将其安装在前缀路径下。我假设您需要将版本号更改为适当的数字。
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库
Libs: -L${libdir} -lclntsh
Cflags: -I${includedir}
Version: 11.2
英文:
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
答案2
得分: 0
1、安装goracle。
2、安装TDM GCC。
3、使用sql.open连接到Oracle,这里是一个小例子。
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\n", thedate)
}
来自oracle博客
英文:
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\n", thedate)
}
from oracle blog
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论