函数:
1.
函数查看字符串中共包含几个某特殊字符,如'A**B*CEDF'中包含几个‘*’
2.
函数把员工表中不同的工作连接成一个字符串
3.
函数计算个人所得税,工资,薪金所得减3500,
含税级距 税率(%) 速除数
不超过1500 3 0
超过1500到4500 10 105
超过4500 到9000 20 555
超过9000 到35000 25 1005
--1 create or replace function special_char (c in varchar2,v in varchar2) return number is s_num number; begin s_num:=length(c)-length(replace(c,v,'')); return(s_num); end; declare num number; begin num := special_char('AA****AA','*'); dbms_output.put_line(num); end; --2 create or replace function all_work return varchar2 is wname varchar2(100) ; begin select wm_concat(job) into wname from (select distinct job from emp); return(wname); end all_work; declare wname varchar(100); begin wname:=all_work(); dbms_output.put_line(wname); end; --3 create or replace function tax(p_empno in emp.empno%type) return number is t number ; begin select sal+nvl(comm,0)-3500 into t from emp where empno = p_empno; if t<0 then t:=0; ELSIF t<1500 THEN t:=t*0.03; ELSIF t<4500 THEN t:=t*0.1-105; ELSIF t<9000 THEN t:=t*0.2-555; ELSIF t<35000 THEN t:=t*0.25-1005; end if; return(t); end tax; declare t number; begin t:=tax(7839); dbms_output.put_line(t); end;
版权声明:本文为博主原创文章,未经博主允许不得转载。