创建函数:
CREATE OR REPLACE FUNCTION func1()
RETURNS integer AS $total$ --注意返回值的格式
declare
total integer;
BEGIN
SELECT count(*) into total FROM emp1mot e1m join emp1 e1 on e1.mgr = e1m.mgr;
RETURN total;
END;
$total$ LANGUAGE plpgsql; --这句是必要的
创建存储过程:
CREATE OR REPLACE PROCEDURE proc1()
AS
DECLARE
genre_rec record; --声明记录类型
BEGIN
for genre_rec in (select e1.ename from public.emp1 e1 join public.emp1mot e1m on e1.mgr = e1m.mgr)
loop
RAISE NOTICE '%', genre_rec."ename"; --打印
end loop;
END;
/ --这句是必要的