PL/SQL搜索CASE語句

所搜索的CASE語句沒有選擇WHEN子句包含給布爾值的搜索條件。

語法:

在PL/SQL搜查case語句語法是:

CASE WHEN selector = 'value1' THEN S1; WHEN selector = 'value2' THEN S2; WHEN selector = 'value3' THEN S3; ... ELSE Sn; -- default case END CASE;

流程圖:

case

示例:

DECLARE grade char(1) := 'B'; BEGIN case when grade = 'A' then dbms_output.put_line('Excellent'); when grade = 'B' then dbms_output.put_line('Very good'); when grade = 'C' then dbms_output.put_line('Well done'); when grade = 'D' then dbms_output.put_line('You passed'); when grade = 'F' then dbms_output.put_line('Better try again'); else dbms_output.put_line('No such grade'); end case; END; /

當上述代碼在SQL提示符執行時,它產生了以下結果:

Very good

PL/SQL procedure successfully completed.