在下面的地址,选择你的操作系统版本下载。
https://www.oracle.com/database/technologies/instant-client/downloads.html
比如我这里选的是:
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
目前我的工作中用到的最多的是Version 11.2.0.4.0,所以我下载的版本是。
instantclient-basic-linux.x64-11.2.0.4.0.zip
(基础的)和instantclient-sqlplus-linux.x64-11.2.0.4.0.zip
(可选)
把instantclient-basic-linux.x64-11.2.0.4.0.zip
与instantclient-sqlplus-linux.x64-11.2.0.4.0.zip
解压。解压到哪可能根据自己需要来调整。
我把它们都解压到了如下目录:
~/.soft/instantclient_11_2
我把两个压缩包中的内容全部解压放到一起了。
现在还不可以直接运行,运行会报错如下:
./sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory
需要在环境变量中增加(如:~/.bash_profile增加下面一行):
export LD_LIBRARY_PATH=~/.soft/instantclient_11_2:$LD_LIBRARY_PATH
到这一步,我们直接./sqlplus
是已经可以直接运行了。
./sqlplus
SQL*Plus: Release 11.2.0.4.0 Production on Wed Sep 22 15:16:08 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter user-name:
下面一行增加到~/.bash_profile
export PATH=~/.soft/instantclient_11_2/:$PATH
配置完以后source ~/.bash_profile
使环境变量立即生效。这样随处都可以执行sqlplus了。
创建目录
mkdir -p ~/.soft/instantclient_11_2/network/admin
这是与此即时客户端链接的应用程序的默认Oracle配置目录。如tnsnames.ora
,sqlnet.ora
,ldap.ora
,或 oraaccess.xml
放在这个目录。
tnsnames.ora我用的比较多。
我的配置如下,仅供参考:
# tnsnames.ora Network Configuration File
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
CentOS =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.184.5)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
设置环境变量TNS_ADMIN
为目录名称。
export TNS_ADMIN=~/.soft/instantclient_11_2/network/admin
连接名:CentOS
用户名:usr_sg
密码:manager
sqlplus usr_sg/manager@CentOS
查数据库编码:
select userenv('language') from dual;
我的结果如下:
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
也就是说数据库的编码是:AMERICAN_AMERICA.AL32UTF8
那么在运行 sqlplus前运行:
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
即可临时解决中文乱码的问题。需要永久解决,就加到环境变量中即可。
https://www.cnblogs.com/xqzt/p/4458061.html
column userid format a12
column name format a6
set pagesize 50000
set linesize 32767
文章底部有安装教程
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html