语法:HIST[ORY] [n RUN | EDIT | DEL[ETE]] | [CLEAR | LIST]
功能:使用history命令查看历史SQL命令,并可以再次执行、编辑、删除这些历史命令。
使用history命令的前提是已经set history开启了缓存历史SQL命令的功能。当SQL数量超过了最大保留值时,自动清除最旧的数据,并重新生成从1开始的连续的序号。
set history 100 设置缓存100条历史SQL记录。
set history off 设置关闭缓存。
history 查看所有缓存的历史SQL命令。
history list 查看所有缓存的历史SQL命令。等同于单独执行history命令。
history n run 执行缓存记录中的第n条SQL命令。编号前的星号(*)表示最后执行的SQL。
history n edit 编辑缓存中的第n条SQL命令,编辑后的新SQL作为新记录保存在缓存列表最后,原SQL记录信息不变。
history n delete 删除缓存中的第n条SQL命令,其它历史SQL将重新产生连续的序号。
history clear 清空缓存列表。
在使用编辑命令时,可以先用DEFINE命令设置_EDITOR来指定文本编辑器的名称,如使用vi编辑器:
DEFINE _EDITOR = vi
开启和关闭history功能:
SQL> set history on
SQL> show history
History is ON and set to "100"
SQL> set history off
SQL> show history
History is OFF
SQL> set history 200
SQL> show history
History is ON and set to "200"
查看历史SQL记录:
SQL> show history
history is OFF
SQL> set history on
SQL> show history
history is ON and set to "100"
SQL> select max(id) id from tt;
id
----
23
SQL> select 1 from dual;
1
---
1
SQL> history
1 show history
2 select max(id) id from tt;
3 select 1 from dual;
SQL> history 2 run
id
----
23
SQL> history //编号前的星号(*)表示最后执行的SQL
1 show history
*2 select max(id) id from tt;
3 select 1 from dual;