Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Tips Database Forum Rss Feed

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Rss Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles


Posted Feb 24, 2004

DB2 Command Line Processor Tips and Tricks - Page 2

By DatabaseJournal.com Staff

The HISTORY and RUNCMD Commands

The HISTORY command lets you access the contents of a cache, which, by default, holds up to twenty 20 recently run commands in the same interactive DB2 CLP session. The commands are returned with corresponding sequence numbers that show the order in which the commands were run. The most recently run command is listed last.

The size of the command history cache can be controlled using the DB2_CLPHISTSIZE DB2 registry variable. The range of permissible values is 1 to 500, inclusive. If you set this variable to a value that is outside of this range, the DB2 UDB CLP will use the default size of 20.

The syntax of the HISTORY command is shown below:

For example, note the order in which the commands in the following session were entered:

In the command cache, they are assigned sequence numbers as follows:

	db2 connect to sample [1]
	db2 select * from staff where dept = 20 [2]
	db2 connect reset [3]
	db2 create database Melnyk [4]

You can verify this by entering the HISTORY command:

You can use the REVERSE keyword to reverse the order in which the commands are listed:

You can run any command in the command cache using the RUNCMD command. The syntax of this command is shown below:

The following example shows you how to run a command from the cache:

If the <num> option is not specified, the default behavior is to run the most recent command.

The command history does not persist from session to session; if you leave the prompt, the history is lost. If you start two separate interactive CLP sessions, each session's command history is stored in a separate cache.

DB2 Archives