首页 > 代码库 > oracle 简单SQL

oracle 简单SQL

1,  insert into test select * from test;(造测试数据)

2,  create table b as select * from a; (创建表结构一样的空表,数据可同上插入数据)

 

3,linux系统下让sqlplus支持历史命令回调

在linux中实现上述功能,需要一个小工具,叫做rlwrap,这个程式本身是个Shell,可以运行任何你提供给它的命令包括参数,并添加命令历史浏览功能。 The rlwrap program is under the GPL license。
 
步骤:
1,下载
  rlwrap-0.37.tar.gz 
  下载地址:http://utopia.knoware.nl/~hlub/uck/rlwrap/
2,安装
*注意以下操作要在root用户下执行
[root@localhost ~]$ tar -xzvf rlwrap-0.37.tar.gz
[root@localhost ~]$ cd rlwrap-0.37
[root@localhost rlwrap-0.37]# ./configure
[root@localhost rlwrap-0.37]# make
[root@localhost rlwrap-0.37]# make install
 
或是你用yum搞定吧
先搜下看你的yum repo有没有
yum search rlwarp && yum install -y rlwarp;
 
OK, 安装完毕,接下来就是如何使用了
 
3,使用
切换到oracle 用户下
[root@localhost rlwrap-0.37]# su - oracle
在sqlplus前面加上rlwrap就可以了
[oracle@localhost ~]$ rlwrap sqlplus / as sysdba
 
OK,现在可以试下上下键调用历史命令了,真方便
 
注意:其中rlwrap是一个工具,不仅可以应用在sqlplus上,其它像rman 或者别的工具都可以在其前面加上rlwrap来实现历史命令调用
 
当然每次调用sqlplus前都要敲rlwrap也有些烦,有个办法,就是使用别名,以后就可以更方便的使用sqlplus了,方法如下:
 
alias sqlplus=‘rlwrap sqlplus‘
 
把上面的语名加到.bash_profile里就可以了
 
4,在linux环境下使用sqlplus,在回删(backspace)时往往会出现乱码。
出现乱码是由于oracle的sqlplus不使用gnu的 readline库造成的。   解决方法有两种: 1。要使用回删键(backspace)时,同时按住ctrl键 2。设定环境变量 在bash下:$ stty erase ^?或者把 stty erase ^? 添加到.bash_profile中。 在csh下:$ stty erase ^H或者把 stty erase ^H  添加到.cshrc中。
 
5,oracle sqlplus 简单清屏
clear screen