You can form SQL statements that contain placeholders. They reserve areas in the statements, which are filled in when the statement is performed. One reason for doing this, for example, is to avoid typing an UPDATE statement for each table update. Suppose you want to update the EMPLOYEE table to reflect a $100 bonus increase for particular employees.
set autocommit off
This starts a logical unit of work. Now type:
hold update employee - set bonus = &1 - where empno = '&2'
The use of HOLD at the beginning of this example places the UPDATE statement in the command buffer without processing it.
In the example, &1 and &2 are the placeholders. The number following the ampersand refers to the sequence in which the placeholders are replaced. The database manager performs the replacement as follows: the first item of information replaces &1, the second replaces &2, and so on.
start (bonus+100.00 '000010')
This command adds a $100 bonus to employee 000010, and produces a message indicating that one row (ROWCOUNT=1) was updated. The actual UPDATE statement processed is:
update employee set bonus = bonus + 100.00 where empno = '000010'
The two items of information which replace the placeholders are called parameters.
start (bonus+100.00 '000050')
set autocommit on
Respond to the resulting message with the following to prevent the changes from being committed:
rollback
The following are rules for the use of placeholders and parameters:
EXERCISE 2 (Answers are in Appendix A, Answers to the Exercises, page ***.)
|