條件控制語句
阿新 • • 發佈:2018-12-14
1.IF語句
支援的分支結構
IF-THEN-END IF
IF-THEN-ELSE-END IF
IF-THEN-ELSEIF-END IF
IF condition THEN
statements;
[ELSEIF condition THEN
statements;]
[ELSE
statements;]
END IF;
declare
v1 date := to_date('01-01-2016','mm-dd-yyyy');
v2 boolean;
begin
if months_between(sysdate,v1) >5 then
v2:= true;
dbms_output.put_line('true');
else
v2:=false;
dbms_output.put_line('false');
end if;
end;
/
2.CASE語句
declare
v1 char(1) := upper('&v1');
v2 varchar2(20);
begin
v2:= case v1
when 'A' then 'grade is A'
when 'B' then 'grade is B'
when 'C' then 'grade is C'
else 'no such grade'
end;
dbms_output.put_line(v2);
end;
/