如何使用包Oracle.jl从julia连接到Oracle XE 11g2?

问题描述 投票:1回答:1

我试图使用Oracle.jl从julia连接到Oracle XE 11g2,如下所示。

环境:CentOS 7.5 64bit CentOS 7.5 64bit

a) 已下载 instantclient-basic-linux.x64-19.6.0.0.0dbru.zip 并解压到stdlib文件夹 /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4

b) julia配置 etcprofile.djulia.sh内容。

#!/bin/sh
export JULIA_HOME=/opt/julia/julia-1.4.1
export JULIA_LOAD_PATH=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
export JULIA_DEPOT_PATH=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
export JULIA_PKG_DEVDIR=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
export JULIA_PROJECT=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
export JULIA_HISTORY=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/logs/repl_history.jl
export PATH=$JULIA_HOME/bin:$PATH

c) julia脚本,oraConnTest.jl内容。

import Oracle
global const dbHost = "localhost";
global const dbClientType = "thin";
global const dbName = "xe";
global const dbPort = "1521";
global const schema = "test";
global const dbUserPassword = "test2357";
global const conn_str="//"*dbHost*":"*dbPort*"/"*dbName;

conn = Oracle.Connection(dbUserName, dbUserPassword, conn_str);
rs=Oracle.query(conn, "SELECT * FROM TAB");
println(rs[:,1])
conn.close();

我得到以下错误。

julia> include("/root/oraConnTest.jl")
ERROR: LoadError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". 

更新1。

但是,我的JULIA_LOAD_PATH里有libclntsh.so,如下所示。

[root@srvr0 ~]# find / -name libclntsh.so
/index/instantclient_19_6/libclntsh.so
/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/instantclient_19_6/libclntsh.so
/u01/app/oracle/product/11.2.0/xe/lib/libclntsh.so

日志。

[root@srvr0 ~]# cat /etc/profile.d/julia.sh
#!/bin/sh
export JULIA_HOME=/opt/julia/julia-1.4.1
export JULIA_LOAD_PATH=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
export JULIA_DEPOT_PATH=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
export JULIA_PKG_DEVDIR=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
export JULIA_PROJECT=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
export JULIA_HISTORY=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/logs/repl_history.jl
export ORA_INST_CLNT_PATH=/index/instantclient_19_6
#export ORA_INST_CLNT_PATH=/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/instantclient_19_6
#export ORA_INST_CLNT_PATH=/u01/app/oracle/product/11.2.0/xe/lib/
export PATH=$ORA_INST_CLNT_PATH:$JULIA_HOME/bin:$PATH

julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7 CPU       M 620  @ 2.67GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, westmere)
Environment:
  JULIA_DEPOT_PATH = /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
  JULIA_PROJECT = /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
  JULIA_LOAD_PATH = /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
  JULIA_PKG_DEVDIR = /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4
  JULIA_HOME = /opt/julia/julia-1.4.1
  JULIA_HISTORY = /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/logs/repl_history.jl

(v1.4) pkg> rm Oracle.jl
   Updating `@stdlib/Project.toml`
  [7240a794] - Oracle v0.1.0
   Updating `@stdlib/Manifest.toml`
  [7240a794] - Oracle v0.1.0
  [ade2ca70] - Dates 
  [8f399da3] - Libdl 
  [de0858da] - Printf 
  [4ec0a83e] - Unicode 

(v1.4) pkg> add Oracle.jl
   Updating registry at `@stdlib/General`
   Updating git-repo `https://github.com/JuliaRegistries/General.git`
┌ Warning: Some registries failed to update:
│     — /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/registries/General — failed to fetch from repo
└ @ Pkg.Types /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Pkg/src/Types.jl:1122
  Resolving package versions...
   Updating `@stdlib/Project.toml`
  [7240a794] + Oracle v0.1.0
   Updating `@stdlib/Manifest.toml`
  [7240a794] + Oracle v0.1.0
  [ade2ca70] + Dates 
  [8f399da3] + Libdl 
  [de0858da] + Printf 
  [4ec0a83e] + Unicode 

julia> include("/root/ora.jl")
ERROR: LoadError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help
Stacktrace:
 [1] Oracle.Context() at /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/packages/Oracle/U5383/src/context.jl:25
 [2] #Connection#10 at /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/packages/Oracle/U5383/src/connection.jl:122 [inlined]
 [3] Oracle.Connection(::String, ::String, ::String) at /opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/packages/Oracle/U5383/src/connection.jl:122
 [4] top-level scope at /root/ora.jl:13
 [5] include(::String) at ./client.jl:439
 [6] top-level scope at REPL[5]:1
in expression starting at /root/ora.jl:13

我尝试了find命令中列出的libclntsh.so的所有三个路径。但问题仍然存在。

请帮助我解决上述问题。

oracle julia
1个回答
0
投票

设置 PATH 你的甲骨文 .so 文件。Oracle驱动程序通常需要在 PATH.

export PATH=$PATH:/opt/julia/julia-1.4.1/share/julia/stdlib/v1.4/inst
© www.soinside.com 2019 - 2024. All rights reserved.