1. 程式人生 > >plsqlcase選擇語句

plsqlcase選擇語句

res when har case選擇 語句 then 選擇 select out

case選擇語句的基本形式:

CASE selector

WHEN expression1 THEN result1

WHEN expression2 THEN result2

WHEN expressionN THEN resultN

[ ELSE resultN+1]

END CASE;

基本的運用

DECLARE
V_grade char(1) := upper(‘&p_grade‘);
V_appraisal varchar2(20);
BEGIN
v_appraisal :=
case v_grade
when ‘A‘ then ‘Excellent‘
when ‘B‘ then ‘Very good‘
when ‘c‘ then ‘good‘
else ‘No such grade‘
end;
dbms_output.put_line(‘grade:‘||v_grade||‘Appraisal: ‘||v_appraisal);
END;

plsqlcase選擇語句