一、代码如下
--创建:函数
create function scott.getDeptno
(v_empno in scott.emp.empno%type)
return scott.emp.deptno%type
as
outDept scott.emp.deptno%type;
begin
select deptno into outDept from scott.emp where empno = v_empno;
return outDept;
end;
/
--调用函数
declare
v_deptno scott.emp.deptno%type;
begin
v_deptno := scott.getDeptno(7934);
dbms_output.put_line('员工编号为7934的部门为:' || v_deptno);
end;
/
二、执行结果