sql和plsql都有case,但是自己感觉sql中的case似乎用处更大一些!
SQL> select case sex when '1' then '男' when '0' then '女' else '其它' end sex ,
count(*) from t_emp group by sex;
SEX COUNT(*)
------------------------------ ----------
男 2
其它 3
女 1
SQL>
--=======================================
declare
v_i int default 10 ;
v_j int :=&a ;
v_result number ;
begin
case
when v_j>0 then
v_result := v_i/v_j ;
when v_j = 1 then
v_result := v_i+100 ;
when v_j = 0 then
v_result := -1 ;
end case ;
dbms_output.put_line(v_result) ;
end;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/19602/viewspace-61750/ ,如需转载,请注明出处,否则将追究法律责任。