The IF statement selects different execution paths depending on the evaluation of one or more truth value expressions, given as SQL search conditions.
┌────────────────────────────┐ ►►─── IF ── search-condition ── THEN ── ▼ ─ procedure-statement ─ ; ─┴──────────► ►─┬───────────────────────────────────────────────────────────────────────────┬► │ ┌──────────────────────────────────────────────────────────────────────┐ │ │ │ ┌────────────────────────────┐ │ │ └─ ▼ ─ ELSEIF ── search-condition ─ THEN ─ ▼ ─ procedure-statement ─ ; ─┴─┴─┘ ►─┬───────────────────────────────────────────┬─ END IF ───────────────────────►◄ │ ┌────────────────────────────┐ │ └─ ELSE ──── ▼ ─ procedure-statement ─ ; ─┴─┘
Specifies the truth value expression to be evaluated. The outcome of the evaluation determines the execution path.
Specifies the statements to be executed if the immediately preceding search condition is true.
Specifies the truth value expression to be evaluated if the outcomes of all previously evaluated search conditions are false.
Specifies the statements to be executed if all search conditions are false.
If no alternative execution path is given, execution continues with the next statement outside the IF.
set options command delimiter '++';
create procedure USER01.TIF1
( TITLE varchar(10) with default
, P_LEFT integer
, P_RIGHT real
, RESULT varchar(30)
)
EXTERNAL NAME TIF1 LANGUAGE SQL
Label_200:
begin not atomic
/*
** Compare an integer value with a real value
*/
if (P_LEFT > P_RIGHT)
then set RESULT = 'p_left > p_right';
elseif (P_LEFT = P_RIGHT)
then set RESULT = 'p_left = p_right';
elseif (P_LEFT < P_RIGHT)
then set RESULT = 'p_left < p_right';
else set RESULT = 'p_left and/or p_right NULL !';
end if;
end
++
commit++
call user01.TIF1('Test IF >', 4, 2)++
*+
*+ TITLE P_LEFT P_RIGHT RESULT
*+ ----- ------ ------- ------
*+ Test IF > 4 2.0000000E+00 P_LEFT > P_RIGHT
call user01.TIF1('Test IF <', 4, 9)++
*+
*+ TITLE P_LEFT P_RIGHT RESULT
*+ ----- ------ ------- ------
*+ Test IF < 4 9.0000000E+00 P_LEFT < P_RIGHT
call user01.TIF1('Test IF =', 2, 2)++
*+
*+ TITLE P_LEFT P_RIGHT RESULT
*+ ----- ------ ------- ------
*+ Test IF = 2 2.0000000E+00 P_LEFT = P_RIGHT
call user01.TIF1('Test IF ', 4)++
*+
*+ TITLE P_LEFT P_RIGHT RESULT
*+ ----- ------ ------- ------
*+ Test IF 4 <null> P_LEFT AND/OR P_RIGHT
NULL !
set options command delimiter default++
|
Copyright © 2014 CA.
All rights reserved.
|
|