With a feature that introduced with 12c R2, we can see the history of Sqlplus and run the commands we have run without rewriting.
By default, history is turned off. We need to turn on before use.
Check History is Turned On
1 2 |
SQL> show hist history is OFF |
Turn On History
1 2 3 |
SQL> set hist on SQL> show hist history is ON and set to "100" |
Increase the number of commands to be retained in History
In the following example, we ensure that the last 500 commands in the past are retained.
1 2 3 |
SQL> set hist 500 SQL> show hist history is ON and set to "500" |
Show retained commands in History
1 2 3 4 5 |
SQL> hist 1 show hist 2 select name from v$database; 3 desc v$instance; 4 select INSTANCE_NAME from v$instance; |
Run a command retained in the History again
After detecting the number of the corresponding command as above, we can run the command again as follows.
1 2 3 4 5 |
SQL> hist 2 run NAME --------------------------- ORCL |
Delete a command from the History
1 2 3 4 5 |
SQL> hist 4 del SQL> hist 1 show hist 2 select name from v$database; 3 desc v$instance; |
Clear all commands from the History
1 2 3 |
SQL> hist clear SQL> hist SP2-1651: History list is empty. |