• pl/sql 实例精解 04


    本章主要讨论, IF 语句的应用.

       1:  if condition1 then
       2:    statement1
       3:  elsif condition2 then
       4:    statement2
       5:  else
       6:    statement3
       7:  end if;

    注意: := 用于 PL/SQL 块的赋值操作, = 一般用于 SQL 的赋值操作

       1:  set serveroutput on
       2:   
       3:  declare
       4:      v_student_id    number := 102;
       5:      v_section_id    number := 89;
       6:      v_final_grade    number;
       7:      v_letter_grade    char(1);
       8:  begin
       9:      select final_grade
      10:        into v_final_grade
      11:        from enrollment
      12:       where student_id = v_student_id
      13:         and section_id = v_section_id;
      14:         
      15:      if v_final_grade between 90 and 100 then
      16:          v_letter_grade := 'A';
      17:      elsif v_final_grade between 80 and 89 then
      18:          v_letter_grade := 'B';
      19:      else
      20:          v_letter_grade := 'C';
      21:      end if;
      22:      
      23:      dbms_output.put_line('Letter grade is: ' || v_letter_grade);
      24:  end;
      25:  /
      26:  show errors;

    另外, 还可以使用嵌套的 IF 语句, 及逻辑操作符 and , or, not

  • 相关阅读:
    程序执行并发和并行的理解
    计算机的线程和进程的区别理解,不是编程上的进程和线程
    php单线程理解
    一句话题解(2020.12)
    PE328 Lowest-cost Search
    arc109D
    6908. 【2020.11.30提高组模拟】关灯(light)/loj#3385. 「COCI 2020.11」Svjetlo
    CF1456D. Cakes for Clones
    CF1456C. New Game Plus!
    agc025E
  • 原文地址:https://www.cnblogs.com/moveofgod/p/3651946.html
Copyright © 2020-2023  润新知