if-then-else
Syntax
IF [NOT]
{ Literal1 | :BindVariable1 }
{ = | IN }
{ Literal2 | :BindVariable2 | SelectStatement }
THEN "ThenCommands"
[ ELSE "ElseCommands" ] ;
The ttIsql
IF-THEN-ELSE command has the parameters:
| Parameter | Description |
|---|---|
|
|
The The |
|
|
Using |
|
|
A value that can be part of a comparison. |
|
|
A bind variable is equivalent to a parameter. You can use the
|
|
= | |
You can use the |
|
|
A provided The |
|
|
All commands in the |
Description
The if-then-else command construct enables you to implement
conditional branching logic in a ttIsql session. The IF
command tests a condition and decides whether to run commands within the
THEN clause or the optional ELSE clause. The commands
can be SQL statements, SQL scripts, PL/SQL blocks, or TimesTen utilities.
Example
Command> if :a = 1 then "e:a is 1" else "e:a is not 1";
The following example creates and tests a bind variable to see which type of
locking is enabled for the TimesTen database. It uses the autovariables
command to create the bind variable from the result of the call to
ttConfiguration. The value can be tested within the
IF-THEN-ELSE conditional by testing the paramvalue
variable.
Command> SET AUTOVARIABLES ON;
Command> CALL TTCONFIGURATION('LockLevel');
PARAMNAME, PARAMVALUE
< LockLevel, 0 >
1 row found.
Command> IF :paramvalue = 1 THEN "e:Database-level locking is enabled"
> ELSE "e:Row-level locking is enabled";
Row-level locking is enabled
The following example checks to see that the employees table
exists. If it does not, it runs the SQL script that creates the employees
table; otherwise, a message is printed out.
Command> IF 0 = "SELECT COUNT(*) FROM SYS.TABLES WHERE TBLNAME LIKE 'employees';" THEN "e:EMPLOYEES table already exists" ELSE "@HR_CRE_TT.SQL;"; EMPLOYEES table already exists
Restrictions for the IF-THEN-ELSE construct are as
follows:
-
You cannot compare variables of the LOB data type.
-
The values are compared case-sensitive with
strcmp. A character padded value might not match aVARCHAR2because of the padding.