编写函数返回每个员工的部门名称。在20个部门写一个块打印所有员工姓名和部门名称。函数头:
Create or replace function empdnm (empno number) return varchar2 is
如果没有这样的empno,请尝试编写异常。
我尝试了以下代码,但它显示了一些错误,即
SQL statment ignored and missing expression
. 问题是什么?
create or replace function empdnm (empno1 number) return varchar2 is
deptname varchar (30);
BEGIN
Select into deptname(select d.dname from dept d
join emp e on e.deptno=d.deptno
Where e.empno= empno1
)
exception
WHEN no_data_found THEN
dbms_output.put_line('no employee with no:'|| empno1);
return(deptname);
end;
BEGIN
FOR r IN (SELECT * FROM emp where dept_id = 20) loop
dbms_output.put_line( 'employee '|| r.emp_name || ' is in department '|| empdnm(empno1) );
END loop;
end;