When running SQL * Plus in Linux Shell, the history command line browsing function is not provided. On the contrary, in Windows, when running SQL * Plus in the doscommand window, you can use the up and down keys to jump back to the previously executed SQL statements. You can modify them as needed, and then press [Enter] to submit them again.
To achieve the same purpose in Linux, you can install rlwrap. This program is a Shell and can run any commands you provide to it, including parameters, and add the command history browsing function. The rlwrap program is under the GPL license.
1: Installation
Rlwrap-0.28.tar.gz: http://utopia.knoware.nl /~ Hlub/uck/rlwrap/
1) decompress the Installation File
[Oracle @ Channel-MQ3 ~] $ Gunzip rlwrap-0.28.tar.gz
[Oracle @ Channel-MQ3 ~] $ Tar xvf rlwrap-0.28.tar
2) switch to the root user and run the following command:
[Root @ Channel-MQ3 ~] # Cd/home/oracle/rlwrap-0.28
[Root @ Channel-MQ3 rlwrap-0.28] # ls
Aclocal. m4 completions configure INSTALL README TODO
AUTHORS config. h configure. ac Makefile src tools
Bash30-005.patch config. h. in COPYING Makefile. am stamp-h1
BUGS config. log distribution Makefile. in test
ChangeLog config. status doc NEWS test. log
[Root @ Channel-MQ3 rlwrap-0.28] #./configure
[Root @ Channel-MQ3] # make
[Root @ Channel-MQ3] # make install
2: Use
$ Rlwrap [-options]
[Oracle @ Channel-MQ3 ~] $ Which rlwrap
/Usr/local/bin/rlwrap
[Oracle @ Channel-MQ3 ~] $ Rlwrap sqlplus/as sysdba
SQL * Plus: Release 10.2.0.1.0-Production on Wed Jul 18 10:31:11 2007
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connected:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from v $ sga;
NAME VALUE
------------------------------
Fixed Size 1219856
Variable Size 121635568
Database Buffers 310378496
Redo Buffers' 7168000
-- Use the up key to call back the last command executed, press [Enter] to re-execute or modify it, and then press [Enter] to execute
SQL> select * from v $ sga;
NAME VALUE
------------------------------
Fixed Size 1219856
Variable Size 121635568
Database Buffers 310378496
Redo Buffers' 7168000
In addition, there are many options to set rlwrap
Eg:
−L, −−logfile file
Append command's output (including echo 'ed user input) to file (creating file when it doesn' t exist ).
The test is as follows:
[Oracle @ Channel-MQ3 ~] $ Rlwrap-l benbotest. log sqlplus/as sysdba
SQL * Plus: Release 10.2.0.1.0-Production on Wed Jul 18 10:34:50 2007
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connected:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from v $ version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Prod
PL/SQL Release 10.2.0.1.0-Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0-Production
NLSRTL Version 10.2.0.1.0-Production
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Production
With the Partitioning, OLAP and Data Mining options
[Oracle @ Channel-MQ3 ~] $ Cat benbotest. log
[Rlwrap] Wed Jul 18 10:34:50 2007
SQL * Plus: Release 10.2.0.1.0-Production on Wed Jul 18 10:34:50 2007
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connected:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from v $ version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Prod
PL/SQL Release 10.2.0.1.0-Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0-Production
NLSRTL Version 10.2.0.1.0-Production
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Production
With the Partitioning, OLAP and Data Mining options
[Oracle @ Channel-MQ3 ~] $
Of course, if you think it's hard to repeat rlwrap each time, you can try/etc/profile or your own ~ /. Add alias sqlplus = 'rlwrap sqlplus 'to bashrc '. For other releases, you can select the rpm package or compile the package from the source code.
For other options, See manpage.