PL/SQL流程控制

流程控制
IF-THEN-ELSE语法如下:
IF boolean_expression1 THEN
sequence_of_statements;
[ELSIF Boolean_expression2 THEN
sequence_of_statements;]
...
[ELSE
sequence_of_statements;]
END IF;

CASE的语法结构如下:
CASE test_var
WHEN value1 THEN sequence_of_statement1;
WHEN value2 THEN sequence_of_statement2;
WHEN valuen THEN sequence_of_statementsn;
[ELSE else_sequence;]
END CASE;
CASE语句变化形式
CASE
WHEN test1 THEN sequence_of_statements1;
WHEN test2 THEN sequence_of_statements2;
...
WHEN testn THEN sequence_of_statementsn;
END CASE;

LOOP语句的格式入下:
LOOP
--sequence of statements
END LOOP;
示例:
DECLARE
v_Counter BINARY_INTEGER:=1;
BEGIN
LOOP
--将v_Counter的值插入number_table表中
INSERT INTO number_table(num)
    values(v_Counter);
v_Counter:=v_Counter+1;
--当v_Counter:=20时退出循环
IF v_Counter=20 THEN
    EXIT;
END IF;
END LOOP;
END;

FOR-LOOP语句格式如下:
FOR loop_counter IN [REVERSE] low_bound..high_bound LOOP
sequence of statements
END LOOP;
其中,loop_counter为循环变量,low_bound和high_bound为循环的最小、最大值。
WHILE-LOOP的语法如下:
WHILE condition LOOP
sequence_of_statement;
END LOOP

GOTO语句的语法如下:
GOTO label;

你可能感兴趣的:(流程控制,pl/sql)