CHAPTER 6 Using Procedures and Batches
239
DBISQL and batches
A list of semicolon-separated statements, such as the above, is parsed by
DBISQL before it is sent to the server. In this case, DBISQL sends each
statement individually to the server, not as a batch. Unless you have such
parsing code in your application, the statements would be sent and treated as a
batch. Putting a
BEGIN
and
END
around a set of statements causes DBISQL to
treat them as a batch.
Many statements used in procedures can also be used in batches. You can use
control statements (
CASE
,
IF
,
LOOP
, and so on), including compound
statements (
BEGIN
and
END
), in batches. Compound statements can include
declarations of variables, exceptions, temporary tables, or cursors inside the
compound statement.
The following batch creates a table only if a table of that name does not already
exist:
BEGIN
IF NOT EXISTS (
SELECT * FROM SYSTABLE
WHERE table_name = ’t1’ ) THEN
CREATE TABLE t1 (
firstcol INT PRIMARY KEY,
secondcol CHAR( 30 )
) ;
ELSE
MESSAGE ’Table t1 already exists’ ;
END IF
END
If you run this batch twice from DBISQL, it creates the table the first time you
run it. The next time you run it, it prints the message in the server log file on
Unix or on the server message window on Windows NT.
Control statements
There are a number of control statements for logical flow and decision making
in the body of the procedure or in a batch. The following is a list of control
statements available.
Summary of Contents for Adaptive Server IQ 12.4.2
Page 1: ...Administration and Performance Guide Adaptive Server IQ 12 4 2 ...
Page 16: ...xvi ...
Page 20: ...Related documents xx ...
Page 40: ...Compatibility with earlier versions 20 ...
Page 118: ...Troubleshooting startup shutdown and connections 98 ...
Page 248: ...Importing data by replication 228 ...
Page 306: ...Integrity rules in the system tables 286 ...
Page 334: ...Cursors in transactions 314 ...
Page 396: ...Users and permissions in the system tables 376 ...
Page 438: ...Determining your data backup and recovery strategy 418 ...
Page 484: ...Network performance 464 ...
Page 500: ...System utilities to monitor CPU use 480 ...
Page 514: ...Characteristics of Open Client and jConnect connections 494 ...
Page 536: ...Index 516 ...