Flow control statement [loop, condition]
Read the catalogue-a simple loop
Declare-declare mynum number (3): = 0; begin loop mynum: = mynum + 1; dbms_output.put_line (mynum); exit when mynum = 200;-- exit loop condition end loop;end
-- while cycle
Declare i number: = 1 begin while I 100 then goto biaoji; end if; end loop; dbms_output.put_line ('ithen goto biaoji; end if; end loop; dbms_output.put_line' | | I); end
-- if conditional statement
Declare v_value1 number: = 20 position begin if v_value1 < 10 then dbms_output.put_line ('v_value1 < 10'); elsif v_value1 < 20 then-note that elsif is not else if dbms_output.put_line ('v_value1 < 20'); else dbms_output.put_line ('v_value1 greater than or equal to 20'); end if;end
-- case when
Declare v_value1 varchar2 (2): ='A'; v_value2 varchar2 (100); begin v_value2: = case v_value1 when'A 'then' excellent 'when' B 'then' general 'else' bad 'end; dbms_output.put_line (v_value2); end
Declare v_value1 varchar2 (2): ='A'; v_value2 varchar2 (100); begin v_value2: = case when v_value1 ='A 'then' excellent 'when v_value1 =' B' then 'general' else 'bad' end; dbms_output.put_line (v_value2) End
Both of the above are fine, and notice here that case when statements always return a value (unlike if conditional statements).
It can also be used for query results and query conditions
Select case t.c_type when'B' then 'general' when'A 'then' excellent 'else' bad 'end Case when t.c_case_no = '4090003002115000012then' 4090003002015000012' end from tbl_claim t where t.c_case_no = case when t.c_case_no = '4090003002015000012' then' 4090003002015000012' end
-- decodedecode (condition, value 1, translation value 1, value 2, translation value 2. Value n, translation value n, default) select decode ('excellent,' Bad, 'average', 'excellent', 'Bad') from dual
Can be used for query results and query conditions. (but it can't be assigned like case when)
Select decode (t.type, 'average', 'poor') from mytable t where t.c_no = decode (t.c_no, '111', '111', '222')