declare -- 聲明獎金的變量 v_comm emp.comm%type; begin -- 查詢出員工的獎金 select comm into v_comm from emp where empno=&no; -- 判斷如果員工沒有獎金,把基本工資的10%作為獎金 if v_comm is null then update emp set comm=sal*0.1 where empno=&no; --如果原先獎金低於1000,提升到1000 elsif v_comm<1000 then update emp set comm=1000 where empno=&no; -- 其他情況 把獎金提升10% else update emp set comm=comm*1.1 where empno=&no; end if; end;
declare -- 聲明部門編號的變量 v_deptno emp.deptno%type:=&no; begin case v_deptno when 10 then dbms_output.put_line('技術部'); when 20 then dbms_output.put_line('業務部'); when 30 then dbms_output.put_line('開發部'); when 40 then dbms_output.put_line('財務部'); else dbms_output.put_line('您查找的部門不存在'); end case; end;