1. if...then語句sql
if <condition_expression> thenexpress
plsql_sentence;spa
end if; code
declare -- Local variables here v_name1 varchar2(50); v_name2 varchar2(50); begin -- Test statements here v_name1 := 'East'; v_name2 := 'xiaoke'; if length(v_name1) < length(v_name2) then dbms_output.put_line('字符串['||v_name1||']的長度比字符串['||v_name2||']小!'); end if; end;
2. if...then...else語句
if <condition_expression> thenblog
plsql_sentence1;字符串
elseit
plsql_sentence2;io
end if;ast
declare -- Local variables here v_age int := 55; begin -- Test statements here if v_age > 56 then dbms_output.put_line('您能夠申請退休了!'); else dbms_output.put_line('您小於56歲,不能夠申請退休!'); end if; end;
3. if...then...elsif語句
if <condition_expression1> thenclass
plsql_sentence_1;
elsif <condition_expression2> then
plsql_sentence_2;
else
plsql_sentence_n;
end if;
declare -- Local variables here v_month int := 3; begin -- Test statements here if v_month <= 3 then dbms_output.put_line('這是春季!'); elsif v_month <= 6 then dbms_output.put_line('這是夏季!'); elsif v_month <= 9 then dbms_output.put_line('這是秋季!'); elsif v_month <= 12 then dbms_output.put_line('這是冬季!'); else dbms_output.put_line('您輸入的月份不合法!'); end if; end;
4. case語句
case <selector>
when <expression_1> then plsql_sentence_1;
when <expression_2> then plsql_sentence_2;
...
when <expression_n> then plsql_sentence_n;
[else plsql_sentence;]
end case;
declare -- Local variables here v_season int := 3; v_autoInfo varchar2(50); begin -- Test statements here case v_season when 1 then v_autoInfo := v_season || '季度包括1,2,3月份'; when 2 then v_autoInfo := v_season || '季度包括4,5,6月份'; when 3 then v_autoInfo := v_season || '季度包括7,8,9月份'; when 4 then v_autoInfo := v_season || '季度包括10,11,12月份'; else v_autoInfo := v_season || '季度不合法'; end case; dbms_output.put_line(v_autoInfo); end;