In 12c, Oracle introduced the History command, which is much like the history in the Shell, reducing the knock-down of SQL and bringing a lot of convenience.
1. View the history Help
Sql> Help
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 would list all entries in the list.
2. hist syntax
Hist[ory] [N {RUN | EDIT | Del[ete]}] | [CLEAR]
3. Hist is turned off by default, and is automatically closed after each session disconnects, and the hist list is emptied when hist is closed.
Sql> history;
Sp2-1650:history is off, the use "SET hist[ory] on" to enable the history.
4. Turn hist on or off
Sql> set hist on;
Sql> set hist off;
5. View hist Status
Sql> Show hist;
History is OFF
6. Set the number of records retained by the Hist, the default number of reserved Records is 100
Sql>set History 3;
7. View Hist retained Records
Sql> hist list;
1 show Con_name
2 show parameter version;
3 Show hist;
Description: The number of records retained is calculated by command rather than by line count.
8. Run the specified record
Sql> hist;
1 Select sysdate from dual;
2 show Con_name
3 Select date from dual;
Sql> hist 2 run;
Con_name
------------------------------
Cdb$root
9. Edit the previous command
hist 1 edit;
Description: You can operate like Linux VI and edit the retained record to the end of the number of records.
10. Delete the specified number of records
hist 2 del
11. Clear All Records
Sql> hist Clear;
Oracle 12C new features Sqlplus view the history command