我收到错误消息,因为“子查询必须仅返回一列”。因为我每个部门都有更多的员工。告诉我解决此问题的解决方案
CREATE OR REPLACE FUNCTION dept_emp()
RETURNS TEXT AS
$$
DECLARE
cur_dept CURSOR FOR SELECT dept_name FROM dept;
cur_emp CURSOR FOR SELECT employee_id,dob,department FROM emp;
d RECORD;
e RECORD;
BEGIN
FOR d IN SELECT dept_name FROM dept
LOOP
FOR e IN SELECT employee_id,dob,department FROM emp
LOOP
RAISE NOTICE 'Department: %',d.dept_name;
RETURN (SELECT employee_id,dob FROM emp WHERE d.dept_name=e.department);
END LOOP;
END LOOP;
END;
$$ LANGUAGE 'plpgsql';