IF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| IF <EXPRESSION1> THEN OPERATION1; END IF; IF <EXPRESSION1> THEN OPERATION1; ELSE OPERATION2; END IF; IF <EXPRESSION1> THEN OPERATION1; ELSIF <EXPRESSION1> THEN OPERATION2; …… ELSE OPERATION3; END IF;
|
CASE
如果case语句没有用else并且when中没有匹配项,将会返回一个错误。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| SET SERVEROUTPUT ON DECLARE i number:=1; BEGIN CASE i WHEN 0 THEN dbms_output.put_line('i is 0'); WHEN 1 THEN dbms_output.put_line('i is 1'); ELSE dbms_output.put_line('i is more than 1'); END CASE END; /
|
循环
LOOP无条件循环
exit when 是可选项,不写的话就永远循环下去了
1 2 3 4
| LOOP OPERATION1 EXIT WHEN <EXPRESSIOIN1>; END LOOP;
|
WHILE循环
1 2 3
| WHILE <EXPRESSION1> LOOP OPEARATOIN1 END LOOP;
|
FOR循环
当在IN 后面输入REVERSE后,是在要求范围内降序循环
1 2 3 4 5 6 7 8 9 10
| SET SERVEROUTPUT ON DECLARE sum number:=0; BEGIN FOR i IN 1..100 LOOP sum:=sum+i; END LOOP; dbms_output.put_line('sum is '|| sum); END; /
|
GOTO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| SET SERVEROUTPUT ON DECLARE SUM number:=0; BEGIN IF SUM > 0 THEN GOTO position1; ELSIF SUM<=0 THEN GOTO position2; END IF; <<position1>> dbms_output.put_line('Here is position1'); <<position2>> dbms_output.put_line('Here is position2'); END; /
|