dropFUNCTIONifexists query_sal_more_than_sb;createorreplaceFUNCTION query_sal_more_than_sb(emp_name text)returnstable(e_ename text, e_sal integer)LANGUAGE plpgsql
AS
$$BEGINreturn query select ename, sal from emp where sal >(select sal from emp where ename = emp_name);END
$$;
select*from query_sal_more_than_sb('ALLEN')
setof
dropFUNCTIONifexists query_sal_more_than_sb;createorreplaceFUNCTION query_sal_more_than_sb(emp_name text)returns setof emp
LANGUAGE plpgsql
AS
$$BEGINreturn query select*from emp where sal >(select sal from emp where ename = emp_name);END
$$;
员工数量
dropFUNCTIONifexists query_emp_count;createorreplaceFUNCTION query_emp_count()returnsintegerLANGUAGE plpgsql
AS
$$DECLARE
emp_count integer;BEGINselectcount(1)into emp_count from emp;return emp_count;END
$$;
dropFUNCTIONifexists get_dept_emp_info;createorreplaceFUNCTION get_dept_emp_info(
dno integer)returnstable(
eno integer,
e_name text,
e_sal integer,
d_name text)LANGUAGE plpgsql
AS
$$DECLARE
info record;BEGINfor info in(select empno, ename, sal, dname from empjoin dept on dept.deptno = emp.deptnowhere emp.deptno = dno)LOOPeno := info.empno;e_name := info.ename;e_sal := info.sal;d_name := info.dname;returnnext;ENDLOOP;END
$$;