As you know that we can repeat our previous SQL*Plus commands in Windows CMD. But in UNIX based systems not supported command line history of SQL*PLus. For this reason in UNIX and Linux, we used
rlwrap utility to see the SQL*Plus command line history and quickly recall previous SQL*Plus commands.
With seconds release of Oracle Database 12c coming SQL*Plus
history command for the history of the command line in Linux.
I want to share some example for this command:
Before using History we must enable history command as below:
SQL> set history on
The syntax of HISTORY command as bellow
SQL> help history
HISTORY
-------
Stores, lists, executes, edits of the commands
entered during the current SQL*Plus session.
HIST[ORY] [N {RUN | EDIT | DEL[ETE]}] | [CLEAR]
N is the entry number listed in the history list.
Use this number to recall, edit or delete the command.
Example:
HIST 3 RUN - will run the 3rd entry from the list.
HIST[ORY] without any option will list all entries in the list.
As you seen from syntax, we can edit, delete, clear list items in history.
SQL> set history on
SQL>
SQL>
SQL> select name from v$database;
NAME
---------
DB122
SQL> select name, database_role from v$database;
NAME DATABASE_ROLE
--------- ----------------
DB122 PRIMARY
SQL>
SQL> select banner from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
PL/SQL Release 12.2.0.1.0 - Production
CORE 12.2.0.1.0 Production
TNS for Linux: Version 12.2.0.1.0 - Production
NLSRTL Version 12.2.0.1.0 - Production
SQL>
SQL>
SQL> hist list
1 select name from v$database;
2 select name, database_role from v$database;
3 select banner from v$version;
SQL>
SQL>
SQL> hist 1 run
NAME
---------
DB122
SQL> hist 3 run
BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
PL/SQL Release 12.2.0.1.0 - Production
CORE 12.2.0.1.0 Production
TNS for Linux: Version 12.2.0.1.0 - Production
NLSRTL Version 12.2.0.1.0 - Production
SQL>
SQL>
SQL> hist clear
SQL>
SQL> hist list
SP2-1651: History list is empty.
SQL>
SQL>
SQL> select name from v$database;
NAME
---------
DB122
SQL> select banner from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
PL/SQL Release 12.2.0.1.0 - Production
CORE 12.2.0.1.0 Production
TNS for Linux: Version 12.2.0.1.0 - Production
NLSRTL Version 12.2.0.1.0 - Production
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
db122
SQL>
SQL>
SQL> hist list
1 select name from v$database;
2 select banner from v$version;
3 select instance_name from v$instance;
SQL>
SQL>
SQL> hist 2 edit
Oracle SQL*Plus using vi editor for editing of history command line.
SQL>
SQL> hist list
1 select name from v$database;
2 select banner from v$version;
3 select instance_name from v$instance;
4 select banner from v$version
where rownum <=1;
SQL> hist 4 run
BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL>
SQL>
SQL> hist clear
SQL>
SQL> set history off
SQL>
SQL>
SQL> hist list
SP2-1650: History is off, use "SET HIST[ORY] ON" to enable History.
SQL>
Please watch for a video tutorial on Youtube:
Best Regards
Mahir M. Quluzade