October 2007
Intermediate to advanced
178 pages
2h 50m
English
PL/SQL includes conditional (IF, CASE) structures as well as sequential control (GOTO, NULL) constructs.
There are several varieties of IF-THEN-ELSE and CASE structures.
IFconditionTHENexecutable statement(s)END IF;
For example:
IF caller_type = 'VIP' THEN
generate_response('GOLD');
END IF;IFconditionTHENTRUE sequence_of_executable_statement(s)ELSEFALSE/NULL sequence_of_executable_statement(s)END IF;
For example:
IF caller_type = 'VIP' THEN
generate_response('GOLD');
ELSE
generate_response('BRONZE');
END IF;IFcondition-1THENstatements-1ELSIFcondition-NTHENstatements-N[ELSE ELSE statements] END IF;
For example:
IF caller_type = 'VIP' THEN
generate_response('GOLD');
ELSIF priority_client THEN
generate_response('SILVER');
ELSE
generate_response('BRONZE');
END IF;There are two types of CASE statements: simple and searched.
A simple CASE statement is similar to an IF-THEN-ELSIF structure. The statement has a switch expression immediately after the keyword CASE. The expression is evaluated and compared to the value in each WHEN clause. The first WHEN clause with a matching value is executed, and then control passes to the next statement following the END CASE. For example:
CASE region_id
WHEN 'NE' THEN
mgr_name := 'MINER';
WHEN 'SE' THEN
mgr_name := 'KOOI';
ELSE mgr_name := 'LANE';
END CASE;If a switch expression evaluates to NULL, ...