以员工号为参数,返回该员工所在部门的平裤基逗均工资
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 procedure 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 dual;
扩展资料:
创建一个函数穗迅,以员工号为参数,返回该员工所在的部门的平均工资。
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 dual; 租肢
return number
is
average number
begin
select ave(员工表.工资) into average
from 员工表,(select 部门号神野滚 from 员工表 where 员工号=员工号) 表2
where 员工表.部门号 = 表2.部门脊模号 ;
return average;
end
时间紧,写得比较粗糙。可能格式上有点错误。 函数里的汉语你改游余成相应的表跟表项就ok了