
September 19th, 2012, 02:16 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 2
Time spent in forums: 4 m 25 sec
Reputation Power: 0
|
|
Question on Function
I am trying to create a function to list all the employee's first name . When I issue the command , I get the result set enclosed with parenthesis . How to display the result set as a list.
Please see example below and advise.
Thanks in advance.
create table emp
( empno integer ,
empfname varchar(50) ,
emplname varchar(50)
);
insert into emp values ( 1 , 'EF' , 'Codd') ;
insert into emp values ( 2 , 'Alan' , 'Turing') ;
insert into emp values ( 3 , 'Al' , 'Biruni ') ;
CREATE OR REPLACE FUNCTION list_all_emps()
RETURNS SETOF character AS
$BODY$
DECLARE
rec record;
BEGIN
FOR rec IN (Select empfname from emp order by empfname asc ) LOOP
RETURN NEXT rec;
END LOOP;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
Select * from list_all_emps()
"(Al)"
"(Alan)"
"(EF)"
|