12CR2 SQL*PLUS History Command

Share via:

Dear Readers,

In this article, we will see the 12CR2 SQL*PLUS History Command

In version 12CR2 Oracle introduced the history command which helps the users to reissue the previously executed commands.

Which decreases the time to write the repeated syntaxes every time.

By default the feature is inactive. We need to enable it in Two ways

 

 

Fire the history or hist to check whether the history is enable or disabled.

SQL> hist

SP2-1650: History is off, use “SET HIST[ORY] ON” to enable History.

You can get all information regarding the history command by using HELP.

SQL> help hist

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.

You need to enable it to start using history.

SQL> set hist on

 

Fire the history or hist to check whether the history is enable or disabled and what are  the previously executed commands available.

SQL> hist

SP2-1651: History list is empty.

 

After enable the history execute some commands which will maintain in history.

SQL> select name from v$database;

NAME

———

TESTDB

 

SQL> select name from v$controlfile;

NAME

——————————————————————————–

/u01/oradata/testdb/TESTDB/controlfile/o1_mf_dt2jqk1q_.ctl

/u01/oradata/testdb/fra/TESTDB/controlfile/o1_mf_dt2jqk5f_.ctl

 

check history what are  the previously executed commands available.

SQL> hist

1  select name from v$database;

2  select name from v$controlfile;

 

If you fire any commands it will append to the history.

 

SQL> archive log list;

Database log mode            No Archive Mode

Automatic archival             Disabled

Archive destination             USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence    1

Current log sequence          3

 

check history what are  the previously executed commands available.

SQL> hist

1  select name from v$database;

2  select name from v$controlfile;

3  archive log list;

 

If you want to execute(RUN) commands available in History you can use the number of command.

SQL> hist 1 run

NAME

———

TESTDB

SQL> hist 3 run

Database log mode               No Archive Mode

Automatic archival                Disabled

Archive destination                USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence    1

Current log sequence             3

 

If you want to edit any commands available in History you can use the number of command the edited command will append to the history.

 

SQL> hist

1  select name from v$database;

2  select name from v$controlfile;

3  archive log list;

 

SQL> hist 1 edit

 

EDIT THE SYNTAX

select log_mode from v$database;

 

SQL> hist

1  select name from v$database;

2  select name from v$controlfile;

3  archive log list;

4  select log_mode from v$database;

 

Run the edited command 4.

SQL> hist 4 run

 

LOG_MODE

————

NOARCHIVELOG

 

 

If you want to delete any commands available in History you can use the number.

 

SQL> hist

1  select name from v$database;

2  select name from v$controlfile;

3  archive log list;

4  select log_mode from v$database;

 

SQL> hist 3 del

 

SQL> hist

1  select name from v$database;

2  select name from v$controlfile;

3  select log_mode from v$database;

 

You can remove the all commands available in History by using Clear.

 

SQL> hist clear

 

SQL> hist

SP2-1651: History list is empty.

 

SQL> select name from v$database;

NAME

———

TESTDB

 

SQL> hist

1  select name from v$database;

 

Show history will display how many statements it can store at present.

 

SQL> show hist

history is ON and set to “100”

Specifying a number how many statements should be kept in the history.

SQL> set hist 500;

SQL> show hist;

history is ON and set to “500”

 

 

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (26 votes, average: 5.00 out of 5)
Loading...

6 thoughts on “12CR2 SQL*PLUS History Command

Add Comment