--Multiple IF statements ( note: BEGIN END, IF condition then,elsif condition Then,else ... END IF )
begin
if FALSE then
Dbms_output.put_line (' Execute if statement ... ');
elsif True then
Dbms_output.put_line (' Execute ELEIF1 statement ... ');
elsif TRUE then
Dbms_output.put_line (' Execute ELEIF2 statement ... ');
elsif FALSE then
Dbms_output.put_line (' Execute ELEIF3 statement ... ');
end IF;
end;
--percentile results converted to five points and printed output
DECLARE
V_score Number (3): = ' &score ';
BEGIN
IF v_score>90 Then
Dbms_output.put_line (' A ');
elsif v_score>80 Then
Dbms_output.put_line (' B ');
elsif v_score>70 Then
Dbms_output.put_line (' C ');
elsif v_score>60 Then
Dbms_output.put_line (' D ');
ELSE
Dbms_output.put_line (' E ');
END IF;
END;
--case Demonstration ( Note: BEGIN end,case subject, when condition then,else...,endcase)
DECLARE
V_light VARCHAR2 (Ten): = ' &light ';
BEGIN
Case V_light
when ' Red light ' then
Dbms_output.put_line (' Stop ');
when ' Green light ' then
Dbms_output.put_line (' line ');
when ' Yellow light ' Then
Dbms_output.put_line (' et ');
ELSE
Dbms_output.put_line (' The information you entered is incorrect. ‘);
END case;
END;
--for Loop ( Note: BEGIN end,loop. EXIT when TRUE: END LOOP)
BEGIN
LOOP
Dbms_output.put_line (' information ... ');
EXIT when TRUE;
END LOOP;
END;
--Let the above loop execute 5 times
DECLARE
V_i Number (10): = 0;
BEGIN
LOOP
Dbms_output.put_line (' information ... ');
V_i: = v_i + 1;
EXIT when v_i=5;
END LOOP;
END;
Oracle: Control statement IF. elsif statement, Case statement, for Loop statement