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;
流程图
示例
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.