oracle中sqlplus客户端安装与使用

oracle中sqlplus客户端安装与使用

转载自这篇文章

一、windows7安装sqlplus客户端

  • 1.解压11.2.0.3.iso里的instantclient-basic-nt-11.2.0.3.0.zip和instantclient-sqlplus-nt-11.2.0.3.0.zip,然后将文件放到C:\OraClient目录下。

  • 2.修改系统环境变量,计算机-系统属性-高级-环境变量-系统变量:
    ORACLE_HOME C:\OraClient
    ORACLE_BASE C:\OraClient
    path C:\OraClient

  • 3.cmd打开C:\OraClient\sqlplus.exe,远程连接oracle数据库,如下图:

     

    1.jpg

scott/[email protected]:1522/wyzc11g

如果连不上,临时关闭防火墙试试:[root@wyzc ~]# service iptables stop

  • 4.创建文件C:\OraClient\network\admin\tnsnames.ora,编辑其,添加以下内容:
WYZC10G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.137.6)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = wyzc10g)
    )
  )

打开sqlplus,连接远程服务器,直接 scott/tiger@wyzc10g 即可。

SQL*Plus: Release 11.2.0.3.0 Production on Sat Feb 10 10:51:26 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Enter user-name: scott/tiger@wyzc10g

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining Scoring Engine
and Real Application Testing options

SQL>

二、linux安装sqlplus客户端

  • 1.虚拟机挂载11.2.0.3-64bit.iso
[root@wyzc Desktop]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@wyzc Desktop]# ls /mnt/oracle-*
/mnt/oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
/mnt/oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm
/mnt/oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.src.rpm
/mnt/oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64.rpm
/mnt/oracle-validated-1.1.0-14.el6.src.rpm
/mnt/oracle-validated-1.1.0-14.el6.x86_64.rpm
/mnt/oracle-validated-1.1.0-14.ol6.src.rpm
/mnt/oracle-validated-1.1.0-14.ol6.x86_64.rpm
[root@wyzc Desktop]# ls /mnt/oracle-instantclient11.2-*
/mnt/oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
/mnt/oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.x86_64.rpm
[root@wyzc Desktop]# rpm -ivh  /mnt/oracle-instantclient11.2-*.rpm
Preparing...                ########################################### [100%]
   1:oracle-instantclient11.########################################### [ 50%]
   2:oracle-instantclient11.########################################### [100%]
    1. 安装sqlplus
[root@wyzc Desktop]# rpm -ql oracle-instantclient11.2-sqlplus
/usr/bin/sqlplus64
/usr/lib/oracle/11.2/client64/bin/sqlplus
/usr/lib/oracle/11.2/client64/lib/glogin.sql
/usr/lib/oracle/11.2/client64/lib/libsqlplus.so
/usr/lib/oracle/11.2/client64/lib/libsqlplusic.so

[root@wyzc Desktop]# export ORACLE_BASE=/usr/lib/oracle/11.2/client64
[root@wyzc Desktop]# export ORACLE_HOME=/usr/lib/oracle/11.2/client64
[root@wyzc Desktop]# export ORACLE_BASE=/usr/lib/oracle/11.2/client64
[root@wyzc Desktop]# export PATH=$ORACLE_HOME/bin:$PATH
[root@wyzc Desktop]# export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

[root@wyzc Desktop]# sqlplus scott/tiger@wyzc:1521/wyzc10g
SQL*Plus: Release 11.2.0.3.0 Production on Sat Feb 10 11:40:01 2018
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining Scoring Engine
and Real Application Testing options
SQL> exit
.....................
[root@wyzc Desktop]# sqlplus scott/tiger@wyzc:1522/wyzc11g
SQL*Plus: Release 11.2.0.3.0 Production on Sat Feb 10 11:40:11 2018
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> 

# 简化写法:

[root@wyzc Desktop]# mkdir $ORACLE_HOME/network/admin -p
[root@wyzc Desktop]# cp /u01/oracle/10g/network/admin/tnsnames.ora 
                        $ORACLE_HOME/network/admin
[root@wyzc Desktop]# sqlplus hr/hr@wyzc10g
SQL*Plus: Release 11.2.0.3.0 Production on Sat Feb 10 12:07:19 2018
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining Scoring Engine
and Real Application Testing options
SQL> 

三、sqlplus命令历史翻页

虚拟机加载11.2.0.3-64bit.iso

[root@wyzc Desktop]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@wyzc ~]# cd /tmp
    1. uniread
[root@wyzc tmp]# ls /mnt/Term-*
/mnt/Term-ReadLine-Gnu-1.16.tar.gz
[root@wyzc tmp]# ls /mnt/IO-*
/mnt/IO-Tty-1.07.tar.gz
[root@wyzc tmp]# ls /mnt/un*
/mnt/uniread-1.01.tar.gz
[root@wyzc tmp]# tar -xzvf /mnt/Term-ReadLine-Gnu-1.16.tar.gz 
[root@wyzc tmp]# tar -xzvf /IO-Tty-1.07.tar.gz 
[root@wyzc tmp]# tar -xzvf /mnt/uniread-1.01.tar.gz 

[root@wyzc IO-Tty-1.07]# perl Makefile.PL 
[root@wyzc IO-Tty-1.07]# make
[root@wyzc IO-Tty-1.07]# make install

[root@wyzc IO-Tty-1.07]# cd ../Term-ReadLine-Gnu-1.16/
[root@wyzc Term-ReadLine-Gnu-1.16]# perl Makefile.PL ; make ; make install

# uniread这个包,要放到最后装

[root@wyzc Term-ReadLine-Gnu-1.16]# cd ../uniread-1.01/
[root@wyzc uniread-1.01]# perl Makefile.PL ; make ; make instal

[root@wyzc uniread-1.01]# su - oracle
[oracle@wyzc ~]$ 10g 
[oracle@wyzc ~]$ uniread  sqlplus scott/tiger
[uniread] Loaded history (0 lines)
SQL*Plus: Release 10.2.0.5.0 - Production on Sat Feb 10 12:26:52 2018
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining Scoring Engine
and Real Application Testing options
SQL> select * from tab; 
select * from tab;
TNAME                  TABTYPE  CLUSTERID
------------------------------ ------- ----------
DEPT                   TABLE
EMP                TABLE
BONUS                  TABLE
SALGRADE               TABLE

SQL> desc dept; #此时,这里便可以回删、上下翻页等。
desc dept;
 Name                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 DEPTNO                    NOT NULL NUMBER(2)
 DNAME                          VARCHAR2(14)
 LOC                            VARCHAR2(13)
SQL> 
    1. rlwrap
[root@wyzc tmp]# ls /mnt/rlwrap-*
/mnt/rlwrap-0.37.tar.gz
[root@wyzc tmp]# tar zxvf /mnt/rlwrap-0.37.tar.gz
[root@wyzc tmp]# cd rlwrap-0.37/
[root@wyzc rlwrap-0.37]# ./configure ; make ; make install
[root@wyzc rlwrap-0.37]# su - oracle 
[oracle@wyzc ~]$ 11g
[oracle@wyzc ~]$ rlwrap  sqlplus hr/hr
SQL*Plus: Release 11.2.0.3.0 Production on Sat Feb 10 12:34:29 2018
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> select * from tab;
TNAME                  TABTYPE  CLUSTERID
------------------------------ ------- ----------
COUNTRIES              TABLE
DEPARTMENTS            TABLE
EMPLOYEES              TABLE
EMP_DETAILS_VIEW           VIEW
JOBS                   TABLE
JOB_HISTORY            TABLE
LOCATIONS              TABLE
REGIONS                TABLE
8 rows selected.
SQL> desc jobs
 Name                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 JOB_ID                    NOT NULL VARCHAR2(10)
 JOB_TITLE                 NOT NULL VARCHAR2(35)
 MIN_SALARY                     NUMBER(6)
 MAX_SALARY                     NUMBER(6)
SQL> 

四、sqlplus显示中文

若是SecureCRT或者Xshell软件,请先修改字符编码为utf-8,对应的设置export NLS_LANG="simplified chinese_china.al32utf8",
也可以直接写入文件.nls。

  • 方法1. export参数

$ export NLS_LANG="simplified chinese_china.al32utf8"

  • 方法2. 修改配置单数
    修改.bash_profile 中的参数,添加相关信息
NLS_LANG="simplified chinese_china.al32utf8";
Export NLS_LANG;
[oracle@wyzc ~]$ 11g
[oracle@wyzc ~]$ sqlplus hr/hr
SQL*Plus: Release 11.2.0.3.0 Production on 星期六 2月 10 12:58:05 2018
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
连接到: 
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> 

或者创建.nls文件:

[oracle@wyzc ~]$ vim .nls
export NLS_LANG="simplified chinese_china.al32utf8"
[oracle@wyzc ~]$ . .nls
[oracle@wyzc ~]$ sqlplus hr/hr
SQL*Plus: Release 11.2.0.3.0 Production on 星期六 2月 10 12:51:05 2018
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
连接到: 
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> exit
  • windows环境:

C:> NLS_LANG="simplified chinese_china.zhs16gbk"
或者添加一个环境变量就可以了。

  • 补充一点知识:
    Nls_lang 是Linux 系统的环境变量;
    Nls_language 是数据库的参数。

五、sqlplus编辑文件

  • 1.edit/ed 编辑文件
    define_editor= 'vi'
SQL> define
DEFINE _DATE           = "09-FEB-18" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "wyzc11g" (CHAR)
DEFINE _USER           = "HR" (CHAR)
DEFINE _PRIVILEGE      = "" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000300" (CHAR)
DEFINE _EDITOR         = "ed" (CHAR)  # 默认编辑器ed
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 
11.2.0.3.0 - 64bit Production With the Partitioning, Oracle Label Security, 
OLAP, Data Mining,Oracle Database Vault and Real Application 
Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000300" (CHAR)
SQL> define _editor='vi' # 临时修改编辑器为vi
SQL> ed /tmp/a.sql
...这里就可以使用vi编辑器,来编辑文档了。
SQL> 
    1. 永久修改为“vi”
[oracle@wyzc ~]$ vim ~/login.sql #永久修改编辑器为vi
define _editor='vi'  
    1. 使用host:
SQL> host
[oracle@wyzc ~]$ vim ~/abc.txt
[oracle@wyzc ~]$ 
[oracle@wyzc ~]$ exit
exit
SQL> 

六、spool [rep/append]

屏幕输出保留到指定文件中,如果文件存在想替换内容使用replace,
追加内容到文件中使用append,
关闭屏幕内容输出到文件使用spool off

SQL> spool /tmp/a.txt                             
SQL> select * from tab;
TNAME                  TABTYPE  CLUSTERID
------------------------------ ------- ----------
COUNTRIES              TABLE
DEPARTMENTS            TABLE
EMPLOYEES              TABLE
EMP_DETAILS_VIEW           VIEW
JOBS                   TABLE
JOB_HISTORY            TABLE
LOCATIONS              TABLE
REGIONS                TABLE
8 rows selected.
SQL> spool off

SQL> host cat /tmp/a.txt  # 查看

或者下面这样查看:

SQL> host   
[oracle@wyzc ~]$ cat /tmp/a.txt
----- 内容开始
SQL> select * from tab;
TNAME                          TABTYPE  CLUSTERID                               
------------------------------ ------- ----------                               
COUNTRIES                      TABLE                                            
DEPARTMENTS                    TABLE                                            
EMPLOYEES                      TABLE                                            
EMP_DETAILS_VIEW               VIEW                                             
JOBS                           TABLE                                            
JOB_HISTORY                    TABLE                                            
LOCATIONS                      TABLE                                            
REGIONS                        TABLE                                            
8 rows selected.
SQL> spool off
---- 内容结束
[oracle@wyzc ~]$ exit
exit
SQL> 

SQL> spool /tmp/a.txt rep #替换
SQL> spool /tmp/a.txt append #追加

你可能感兴趣的:(oracle中sqlplus客户端安装与使用)