declare
v_emp_beforetax scott.emp.sal%type := 6000;
v_emp_con_tax constant scott.emp.sal%type:= 5000;
v_emp_cal scott.emp.sal%type;
v_tax scott.emp.sal%type;
v_emp_aftertax scott.emp.sal%type;
begin
v_emp_cal := v_emp_beforetax-v_emp_con_tax;
case
when v_emp_cal < 1500 then v_tax := v_emp_cal*0.03-0;
when v_emp_cal > 1500 and v_emp_cal< 3000 then v_tax := v_emp_cal*0.1-100;
when v_emp_cal > 3000 and v_emp_cal < 4500 then v_tax := v_emp_cal*0.15-200;
else v_tax := v_emp_cal*0.3-300;
end case;
v_emp_aftertax := v_emp_beforetax-v_tax;
dbms_output.put_line('税后工资是'||v_emp_aftertax);
exception
when others then --如果产生了异常
dbms_output.put_line('出错');
end;
使用&可以获取用户输入的值
declare
empno number(2);
begin
empno := &no; --使用&可以获取用户输入的值
dbms_output.put_line(empno);
exception
when others then
dbms_output.put_line('Error Code');
end;