关于PLSQL中的流程控制

来源:2-3 PL/SQL中if语句的使用

慕粉2310089285

2017-10-31 12:29

老师,流程控制中的“case”语句好像没有讲到,我在一本书上看到过,好像也是 一种流程控制语句

写回答 关注

2回答

  • 慕粉3810876
    2017-10-31 20:51:39
    已采纳

    case从严格意义上讲是if选择语句,是多条if语句的缩写形式,本质是属于条件判断,和循环流程控制不是一个概念

    慕粉2310...

    非常感谢!

    2017-11-01 19:00:22

    共 1 条回复 >

  • 慕粉4303271
    2017-10-31 20:47:33

    语法:

    CASE selector 

    WHEN exp1 then res1

    WHEN exp2 then res2

    WHEN exp3 then res3

    ...

    [ELSE resN]

    end;

    SQL> declare
    2 mygrade char(1):='A';
    3 res varchar2(20);
    4 begin
    5 res :=
    6 CASE mygrade
    7 WHEN 'A' THEN 'The mark is 90-100'
    8 WHEN 'B' THEN 'The mark is 80-90'
    9 WHEN 'C' THEN 'The mark is 70-80'
    10 WHEN 'D' THEN 'The mark is 60-70'
    11 WHEN 'E' THEN 'The mark is 0-60'
    12 END;
    13 dbms_output.put_line(res);
    14 end;
    15 /
    The mark is 90-100

    PL/SQL procedure successfully completed.

    SQL> 2
    2* mygrade char(1):='A';

    SQL> ch /'A'/'F'/
    2* mygrade char(1):='F';
    SQL> l 
    1 declare
    2 mygrade char(1):='F';
    3 res varchar2(20);
    4 begin
    5 res :=
    6 CASE mygrade
    7 WHEN 'A' THEN 'The mark is 90-100'
    8 WHEN 'B' THEN 'The mark is 80-90'
    9 WHEN 'C' THEN 'The mark is 70-80'
    10 WHEN 'D' THEN 'The mark is 60-70'
    11 WHEN 'E' THEN 'The mark is 0-60'
    12 END;
    13 dbms_output.put_line(res);
    14* end;
    SQL> /

    PL/SQL procedure successfully completed.

    SQL> declare
    2 mygrade char(1):='F';
    3 res varchar2(20);
    4 begin
    5 res :=
    6 CASE mygrade
    7 WHEN 'A' THEN 'The mark is 90-100'
    8 WHEN 'B' THEN 'The mark is 80-90'
    9 WHEN 'C' THEN 'The mark is 70-80'
    10 WHEN 'D' THEN 'The mark is 60-70'
    11 WHEN 'E' THEN 'The mark is 0-60'
    12 ELSE 'The mark is null'
    13 END;
    14 dbms_output.put_line(res);
    15 end;
    16 /
    The mark is null

    PL/SQL procedure successfully completed.


    慕粉2310...

    请问你知道怎么向老师提问吗?

    2017-11-01 20:26:43

    共 1 条回复 >

Oracle数据库开发必备利器之PL/SQL基础

Oracle数据库高级开发必备的基础,通过实例带你熟练掌握

75048 学习 · 208 问题

查看课程

相似问题