PL/SQL 求函数编写 20
创建函数f_tax计算员工需要上缴的所得税,一级工资的雇员不交税,二级工资缴纳5%,三级工资缴纳10%,四级工资缴纳15%。模型就是scott下的那几个表...
创建函数 f_tax 计算员工需要上缴的所得税,一级工资的雇员不交税,二级工资缴纳5%,三级工资缴纳10%,四级工资缴纳15%。
模型就是scott下的那几个表 展开
模型就是scott下的那几个表 展开
2个回答
展开全部
CREATE OR REPLACE FUNCTION F_TAX(P_EMPNO IN EMP.EMPNO%TYPE) RETURN NUMBER AS
V_SAL EMP.SAL%TYPE;
V_RETURN NUMBER(4,2);
V_GRADE SALGRADE.GRADE%TYPE;
BEGIN
V_SAL:=0;
SELECT SAL INTO V_SAL FROM EMP WHERE EMPNO=P_EMPNO;
SELECT GRADE INTO V_GRADE FROM SALGRADE WHERE V_SAL BETWEEN LOSAL AND HISAL;
CASE V_GRADE
WHEN 1 THEN V_RETURN:=0;
WHEN 2 THEN V_RETURN:=V_SAL*0.05;
WHEN 3 THEN V_RETURN:=V_SAL*0.1;
WHEN 4 THEN V_RETURN:=V_SAL*0.15;
ELSE V_RETURN:=0;
END CASE;
RETURN V_RETURN;
EXCEPTION
WHEN OTHERS THEN
V_RETURN:=-1;
RETURN V_RETURN;
END F_TAX;
V_SAL EMP.SAL%TYPE;
V_RETURN NUMBER(4,2);
V_GRADE SALGRADE.GRADE%TYPE;
BEGIN
V_SAL:=0;
SELECT SAL INTO V_SAL FROM EMP WHERE EMPNO=P_EMPNO;
SELECT GRADE INTO V_GRADE FROM SALGRADE WHERE V_SAL BETWEEN LOSAL AND HISAL;
CASE V_GRADE
WHEN 1 THEN V_RETURN:=0;
WHEN 2 THEN V_RETURN:=V_SAL*0.05;
WHEN 3 THEN V_RETURN:=V_SAL*0.1;
WHEN 4 THEN V_RETURN:=V_SAL*0.15;
ELSE V_RETURN:=0;
END CASE;
RETURN V_RETURN;
EXCEPTION
WHEN OTHERS THEN
V_RETURN:=-1;
RETURN V_RETURN;
END F_TAX;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询