oracle if语句和case语句的使用例子
set serveroutput on
declare
v_n1 number(2):=-9;begin
if v_n1=0 then
dbms_output.put_line('这个值是0');
elsif v_n1=1 then
dbms_output.put_line('这个值是1');
elsif v_n1=2 then
dbms_output.put_line('这个值是2');
else
if v_n1<0 then
dbms_output.put_line('是一个负数');
else
dbms_output.put_line('是一个正数');
end if;
end if;
end;
---------------------case-------------------------------------
declare v_date date:=to_date('2017-05-13 12:14:15','YYYY-MM-DD HH24:MI:SS'); v_c varchar2(20); BEGIN v_c:=to_char(v_date,'d'); case v_c when '1' then DBMS_OUTPUT.PUT_LINE('Today is Sunday'); when '2' then DBMS_OUTPUT.PUT_LINE('Today is Monday'); when '3' then DBMS_OUTPUT.PUT_LINE('Today is Tuesday'); when '4' then DBMS_OUTPUT.PUT_LINE('Today is Wendesday'); when '5' then DBMS_OUTPUT.PUT_LINE('Today is Thursday'); when '6' then DBMS_OUTPUT.PUT_LINE('Today is Friday'); else DBMS_OUTPUT.PUT_LINE('Today is Saturday'); end case; END; --第二种写法 declare v_course number; v_list varchar2(100); begin select a into v_course from a; case when v_course >=90 then v_list:='A'; when v_course >=80 then v_list:='B'; when v_course >=70 then v_list:='C'; when v_course >=60 then v_list:='D'; else v_list:='F'; end case; DBMS_OUTPUT.PUT_LINE(v_list); end;
原文链接:https://www.f2er.com/oracle/209283.html