Command History

SQL

Before we can use the HISTORY command we have to make sure it is turned on. In the example below we attempt to use the HISTORY command with no options and we are told the HISTORY command is not enabled, so we enable it as instructed.

SQL> HISTORY
SP2-1650: History is off, use “SET HIST[ORY] ON” to enable History.
SQL> SET HISTORY ON
SQL> HISTORY
SP2-1651: History list is empty.
SQL>
Checking the help for the HISTORY command, we get the following usage.

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.

SQL>
Let’s put some statements in the history and try a few commands.

ALTER SESSION SET NLS_DATE_FORMAT=’DD-MON-YYYY HH24:MI:SS’;
SELECT SYSDATE FROM dual;
SELECT ‘Banana’ FROM dual;

SQL> HISTORY
1 ALTER SESSION SET NLS_DATE_FORMAT=’DD-MON-YYYY HH24:MI:SS’;
2 SELECT SYSDATE FROM dual;
3 SELECT ‘Banana’ FROM dual;

SQL>

SQL> HISTORY 2 RUN

SYSDATE

22-APR-2017 13:49:41

SQL>

SQL> HISTORY 1 DELETE
SQL> HISTORY
1 SELECT SYSDATE FROM dual;
2 SELECT ‘Banana’ FROM dual;

SQL>

Leave a Reply

Your email address will not be published. Required fields are marked *