Oracle 12c Release 2 now provides the ability to reissue the previously executed SQL*Plus commands.
This functionality is similar to the shell history command available on the UNIX platform.
This feature enables us to run, edit, or delete previously executed SQL*Plus, SQL, or PL/SQL commands from the history list in the current session.
We can enable or disable the HISTORY command in the current SQL*Plus session by using the SET HISTORY command.
The HISTORY command enables us to:
• List all commands stored in the history list
• Execute or run an entry in the command history list
• Edit an entry in the command history list
• Delete an entry from the command history list
• Clear all entries stored in the command history list
Usage
HIST[ORY] [n RUN | EDIT | DEL[ETE]] | [CLEAR | LIST]
Check the current HISTORY setting
SQL> show history
history is OFF
Set HISTORY to ON
SQL> set history ON
SQL> show history
history is ON and set to “100”
Change the number of stored entries in the HISTORY list buffer
SQL> set history 500
SQL> show history
history is ON and set to “500”
Execute a few commands from SQL*Plus
SQL> select sysdate from dual;
SYSDATE
———
17-JUL-18
SQL> select name from v$database;
NAME
———
TPPT122
Show the HISTORY list
SQL> history
1 show history
2 select sysdate from dual;
3 select name from v$database;
Execute a command from the HISTORY list
SQL> history 2 run
SYSDATE
———
17-JUL-18
Edit a stored entry and then execute it
SQL> history 3 edit
select name ,open_mode from v$database;
SQL> history
1 show history
2 select sysdate from dual;
3 select name from v$database;
4 select name ,open_mode from v$database;
SQL> history 4 run
NAME OPEN_MODE
——— ——————–
TPPT122 READ WRITE
Clear the HISTORY
SQL> history clear
SQL> history
SP2-1651: History list is emp