一、rlwrap
在 linux中使用sqlplus对数据库进行操作,常常由于敲错命令或需要反复执行某条语句,需要像linux本身有的历史回调的功能, rlwrap 可以用来支持oracle下sqlplus历史命令的回调功能,提高操作效率。
 
1、下载
目前最新版本 rlwrap-0.42.tar.gz (274 k)
 
2、上传到linux服务器上
使用各类文件传输工具将压缩包上传到服务器,如xmanager的xftp工具
 
3、解压缩
[root@OEL ~]# tar -zxvf rlwrap-0.42.tar.gz 
 
4、安装
解压后会产生一个 rlwrap-0.42 文件夹,运行文件夹中的configure文件进行安装
[root@OEL rlwrap-0.42]# ./configure
[root@OEL rlwrap-0.42]#make
[root@OEL rlwrap-0.42]#make install
 
5、安装rlwrap错误问题的解决
 
【You need the GNU readline library(ftp://ftp.gnu.org/gnu/readline/ ) to build this program.】
 
如果安装rlwrap的时候出现上述问题,那么你可能缺失两个包:
 
libtermcap-devel- 2.0.8-46.1.i386.rpm
readline-devel-5.1-1.1.i386.rpm
 
需要在系统光盘或或镜像文件中使用rpm进行安装缺失的软件包后再执行 rlwrap工具的安装
 
6、验证安装的结果
切换到oracle用户使用rlwrap方式登陆到数据库进行测试
[root@OEL ~]# su - oracle
[oracle@OEL ~]$ rlwrap sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 5 10:51:22 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>select status from v$instance;
SQL>select * from v$version;
 
在执行完语句后能使用上下箭头进行指令的回调,并且可以使用backspace退格键进行删除,大大提高了效率
 
7、写入配置文件,方便使用
[oracle@OEL ~]$ vi .bashrc
 
 # User specific aliases and functions
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
alias adrci='rlwrap adrci'

[oracle@OEL ~]$ source .bashrc
 
这样就能在sqlplus下也能有linux系统的查看历史命令的功能了
 
 
 
 
二、glogin.sql文件

oracle数据库安装好之后,默认在$ORACLE_HOME下面的sqlplus/admin/目录里面会有glogin.sql配置文件

这是一个全局的并且会自动运行的配置文件,在客户端使用sqlplus的时候会自动调用这个文件。

因此我们可以在glogin.sql文件里面加入我们经常使用的一些设置,比如要设置登录的用户和实例等。
 
1、设置在登陆sqlplus后显示用户名和实例名
在默认登陆到sqlplus后,只会显示一个SQL>作为的提示符,这样就需要通过指令来查询登陆的用户和实例名称【尤其是在需要切换到不同数据库时,容易造成误操作】
 
在glogin.sql文件中加入下列语句来实现用户名和实例名的显示
 
set sqlprompt "_user'@'_connect_identifier> "
 
 然后再登陆到sqlplus环境中,这样提示符就会变成对应的结果
[oracle@OEL ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 5 11:37:23 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
sys@ORA11>
 
2、设置页面的长宽显示比例
在进行系统维护时,由于部分列名过长,导致查询出来的结果往往显示十分杂乱,不便于查看,这时就需要对页面进行设置
 
在glogin.sql文件中加入两个设置
set linesize 200
set pagesize 9999
设置的值可根据页面的大小修改到合适的结果显示
 
sys@ORA11> set linesize 40
sys@ORA11> select * from v$version;
BANNER
----------------------------------------
Oracle Database 11g Enterprise Edition R
elease 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Prod
uction NLSRTL Version 11.2.0.1.0 - Production
sys@ORA11> set linesize 200
sys@ORA11> / BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
 
3、其他一些常见的设置项
 
set serveroutput on  --设置默认打开dbms_output的输出
define _editor=/usr/local/bin/vim --定义使用的编辑器【定义编辑器为vim,windows平台可设置为notepad】
column object_name format a30 --设置object_name的列长尾30【字符列使用a+数字来表示长度】
column object_id format 999999 --设置object_id列长尾6【数字列需要使用999表示长度,显示多少位就用多少个9表示长度】
 
 
4、查看可设置的选项
可在sqlplus中执行show all,查看当前使用的设置项目
 
 
三、其他常用技巧
 
1、临时返回系统提示符
当在sqlplus中执行维护操作时,想返回到主机提示符下,但又不想退出当前会话,可采用!、ho、host 这3个命令中的任意一个
sys@ORA11> !  --临时返回操作系统提示符下
[oracle@OEL ~]$ ls
database_check.sql database_info.txt oradiag_oracle
database_info.sql Desktop plsql_code
[oracle@OEL ~]$ exit --返回sqlplus提示符下
 
----------------------------------------------------------------
sys@ORA11> ho --临时返回操作系统提示符下
[oracle@OEL ~]$ ls
database_check.sql database_info.txt oradiag_oracle
database_info.sql Desktop plsql_code
[oracle@OEL ~]$ exit --返回sqlplus提示符下
---------------------------------------------------------------
sys@ORA11> host --临时返回操作系统提示符下
[oracle@OEL ~]$ ls
database_check.sql database_info.txt oradiag_oracle
database_info.sql Desktop plsql_code
[oracle@OEL ~]$ exit --返回sqlplus提示符下
 
注:使用rman过程中也能临时返回系统提示符下,但只能使用host指令返回
 
2、oerr指令
oerr可以在Linux系统上查询简短的报错信息的含义,可以快速有效地辅助排查Oracle故障。oerr在oracle软件安装时会一并安装
 
a、oerr的位置
[oracle@OEL ~]$ which oerr
/u01/app/oracle/product/11.2./dbhome_1/bin/oerr --oerr默认在$ORACLE_HOME/bin目录下
 
b、oerr的用法
oerr ora 【errorid】
 
例子:
sys@ORA11> select * from v$instance;
select * from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available
 
[oracle@OEL ~]$ oerr ora
, , "ORACLE not available"
// *Cause: Oracle was not started up. Possible causes include the following:
// - The SGA requires more space than was allocated for it.
// - The operating-system variable pointing to the instance is
// improperly defined.
// *Action: Refer to accompanying messages for possible causes and correct
// the problem mentioned in the other messages.
// If Oracle has been initialized, then on some operating systems,
// verify that Oracle was linked correctly. See the platform
// specific Oracle documentation.
 
通过使用oracle自带的oerr工具能快速了解错误原因并了解如果着手进行处理
 
 
 
 
 
 
 

最新文章

  1. Java连接MySQL数据库——含步骤和代码
  2. pyinstaller--将py文件转化成exe
  3. 【IOS】3. OC 类声明和实现
  4. python 笔记1
  5. 免费Gif图片录制工具
  6. Nginx模块开发-理解HTTP配置
  7. WPFMediaKit照相功能
  8. [MAC OSX - 1] OSX10.10不能安装JKD8,不能使用eclipse
  9. HeaderViewListAdapter cannot be cast to listAdapter问题原因及解决办法
  10. iOS导航栏主题
  11. 201521123051 《Java程序设计》 第二周学习总结
  12. React 之props属性
  13. excel 常用函数和实现功能经验总结积累
  14. tomcat启动,但是访问不了可能的一种状况。
  15. 移动端300ms延迟解决方法在vue 里面的一些小坑
  16. git本地仓库关联多个remote,怎么用本地一个分支向不同remote不同分支推送代码
  17. [Bayes] Metroplis Algorithm --> Gibbs Sampling
  18. 51nod 1057 N的阶乘 (大数运算)
  19. ScheduledExecutorService的使用
  20. Java多线程之CountDownLatch和CyclicBarrier同步屏障的使用

热门文章

  1. javascript Date对象 之 date初始化
  2. poj 3253超时
  3. 批处理文件 bat 的入门命令
  4. 使用axis2构建webservice
  5. 如何实现一个简单的RPC
  6. Autofac is designed to track and dispose of resources for you.
  7. java基础(6)--数组和方法
  8. JavaWeb -- Struts2 构建视图:标签和结果, UI组件标签
  9. imageView图片放大缩小及旋转
  10. H5测试