zoukankan      html  css  js  c++  java
  • 【PL/SQL编程】条件语句

    1. if...then语句

      if <condition_expression> then

        plsql_sentence;

      end if;  

    declare 
      -- Local variables here
      v_name1 varchar2(50);
      v_name2 varchar2(50);
    begin
      -- Test statements here
      v_name1 := 'East';
      v_name2 := 'xiaoke';
      if length(v_name1) < length(v_name2) then
        dbms_output.put_line('字符串['||v_name1||']的长度比字符串['||v_name2||']小!');
      end if;
    end;

    2. if...then...else语句
       if <condition_expression> then

        plsql_sentence1;

      else

        plsql_sentence2;

      end if;

    declare
      -- Local variables here
      v_age int := 55;
    begin
      -- Test statements here
      if v_age > 56 then
        dbms_output.put_line('您可以申请退休了!');
      else
        dbms_output.put_line('您小于56岁,不可以申请退休!');
      end if;
    end;

    3. if...then...elsif语句
      if <condition_expression1> then

        plsql_sentence_1;

      elsif <condition_expression2> then

        plsql_sentence_2;

      else

        plsql_sentence_n;

      end if;

    declare
      -- Local variables here
      v_month int := 3;
    begin
      -- Test statements here
      if v_month <= 3  then
        dbms_output.put_line('这是春季!');
      elsif v_month <= 6 then
        dbms_output.put_line('这是夏季!');
      elsif v_month <= 9 then
        dbms_output.put_line('这是秋季!');
      elsif v_month <= 12 then
        dbms_output.put_line('这是冬季!');
      else
        dbms_output.put_line('您输入的月份不合法!');
      end if;
    end;

    4. case语句
      case <selector>

        when <expression_1> then plsql_sentence_1;

        when <expression_2> then plsql_sentence_2;

        ...

        when <expression_n> then plsql_sentence_n;

        [else plsql_sentence;]

      end case;

    declare
      -- Local variables here
      v_season   int := 3;
      v_autoInfo varchar2(50);
    begin
      -- Test statements here
      case v_season
        when 1 then
          v_autoInfo := v_season || '季度包括1,2,3月份';
        when 2 then
          v_autoInfo := v_season || '季度包括4,5,6月份';
        when 3 then
          v_autoInfo := v_season || '季度包括7,8,9月份';
        when 4 then
          v_autoInfo := v_season || '季度包括10,11,12月份';
        else
          v_autoInfo := v_season || '季度不合法';
      end case;
      dbms_output.put_line(v_autoInfo);
    end;
  • 相关阅读:
    Java安全之对称加密、非对称加密、数字签名
    Java 设计模式 之 中介者模式(Mediator)
    使用jquery获取radio的值
    java6枚举类型
    java http头信息
    怎样用java生成GUID与UUID
    struts2国际化
    JSON.stringify(),JSON.parse(),toJSON()方法使用
    阻塞队列之六:LinkedBlockingDeque
    jQuery给控件赋值....
  • 原文地址:https://www.cnblogs.com/zhuhaiying/p/8043917.html
Copyright © 2011-2022 走看看