位置:首页 > 数据库 > PL/SQL在线教程 > PL/SQL搜索CASE语句

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 statement in PL/SQL

示例:

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.