Oracle條件分支語句示例
Oracle條件分支語句是我們經(jīng)常需要用到的,下面就為您詳細介紹Oracle條件分支語句的語法,如果您對此方面感興趣的話,不妨一看。
Oracle條件分支語句用于依據(jù)特定的情況選擇要執(zhí)行的操作,PL/SQL提供了三種Oracle條件分支語句:if-then, if-then-else,if-then-elsif。
語法如下:
- if conditions then
- statements;
- [elseif conditions then
- statements;]
- [else
- statements;]
- end if;
1、if-then示例
用于執(zhí)行單一條件判斷,如果滿足特定條件則會執(zhí)行相應操作,如果不滿足特定條件則退出條件分支語句。
- declare
- v_count number;
- begin
- select count(*) into v_count from cip_temps;
- if(v_count>0) then
- dbms_output.put_line('v_cont的值:'|| v_count);
- end if;
- end;
- /
2、if-then-else示例
用于執(zhí)行二重條件判斷,如果滿足特定條件則執(zhí)行一組操作,如果不滿足則執(zhí)行另一組操作。
- declare
- v_count number;
- begin
- select count(*) into v_count from cip_temps;
- if(v_count>11) then
- dbms_output.put_line('v_cont的值:'|| v_count);
- else
- dbms_output.put_line('v_count的值:'|| v_count);
- end if;
- end;
- /
3、if-then-elsif示例
用于執(zhí)行多重條件判斷,如果滿足特定條件1則執(zhí)行***組操作,如果滿足特定條件2則執(zhí)行第二組操作,以此類推,如果都不滿足特定條件則執(zhí)行不滿足條件的操作。
- declare
- v_count number;
- begin
- select count(*) into v_count from cip_temps;
- if(v_count>10) then
- dbms_output.put_line('if操作___v_cont的值:'|| v_count);
- elsif (v_count=10) then
- dbms_output.put_line('elsif操作____v_count的值:'|| v_count);
- else
- dbms_output.put_line('else操作____v_cout的值:'||v_count);
- end if;
- end;
- /
【編輯推薦】