本章主要讨论, 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