首页 热点资讯 义务教育 高等教育 出国留学 考研考公

Oracle题:创建一个函数,以员工号为参数,返回该员工所在部门的平均工资...

发布网友

我来回答

3个回答

热心网友

以员工号为参数,返回该员工所在部门的平均工资

create or replace function fun_sal(p_empno emp.empno%type)

return emp.sal%type

as v_sal emp.sal%type;

begin

select avg(sal) into v_sal from emp where deptno=

(select deptno from emp where empno=p_empno);

return v_sal;

end

begin

dbms_output.put_line (fun_sal (7844));

end;

扩展资料

例1:创建一个存储过程,以员工号为参数,输出该员工的工资。

create or replace procere showsal(p_empno emp.empno%type) as v_sal emp.sal%type; begin 

select sal into v_sal from emp where empno=p_empno;  dbms_output.put_line(v_sal); end; begin  showsal(7844); end;

例2:创建一个函数,以部门号为参数,返回该部门的平均工资;

create or replace function fun_avgsal(p_deptno emp.deptno%type) return emp.sal%type as v_sal emp.sal%type; begin

select avg(sal) into v_sal from emp where deptno=p_deptno;  return v_sal; end; begin  dbms_output.put_line (fun_avgsal(10));  end;

热心网友

创建一个函数,以部门号为参数,返回该部门的平均工资。

create or replace function f_sxt6(v_deptno emp.deptno%type) return emp.sal%type is  

vr_sal emp.sal%type;  

begin  

select avg(sal) into vr_sal from emp where deptno = v_deptno;  

return vr_sal;  

end;  

执行  

select f_sxt6(20) 部门平均工资 from al;  



扩展资料:

创建一个函数,以员工号为参数,返回该员工所在的部门的平均工资。  

create or replace function f_sxt7(v_empno emp.empno%type) return emp.sal%type is  

vr_sal emp.sal%type;  

begin  

select avg(sal) into vr_sal from emp where deptno = (select deptno from emp where empno = v_empno);  

return vr_sal;  

end;  

执行: 

select  f_sxt7(7369) from al;  

热心网友

create or replace function fun_ave(员工号 number)
return number
is
average number
begin
select ave(员工表.工资) into average
from 员工表,(select 部门号 from 员工表 where 员工号=员工号) 表2
where 员工表.部门号 = 表2.部门号 ;
return average;
end
时间紧,写得比较粗糙。可能格式上有点错误。 函数里的汉语你改成相应的表跟表项就ok了

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com