原文:http://fengtiejun.iteye.com/blog/1570324
查询数据库table(iteye) 当中id 一样的数据 把把字段的值c_test_user,id链接起来
如
ID c_test_user
1 a
1 c
2 e
3 d
实现的结果
ID c_test_user
1 a,c
2 e
3 d
fetch TAB_CURSOR into c_temp; --把游标当前指向的值赋给变量,然后再向下移动一行。
--- sfindno emp.empno%type 是指:sfindno指定为和emp.empno一样的类型
create or replace function ts_fun(I_ID in number) return varchar2 is
c_temp varchar2(10);
c_test_user varchar2(1000);
cursor TAB_CURSOR is select it.test_user from iteye it where it.ID=I_ID;
begin
open TAB_CURSOR;
loop
fetch TAB_CURSOR into c_temp;
exit when TAB_CURSOR%notfound;
if c_test_user is null then
c_test_user:=c_temp;
else
c_test_user:=c_test_user||','||c_temp;
end if;
end loop;
close TAB_CURSOR;
return c_test_user;
end;
----------------查询----------------------------
select id,ts_fun(id) from iteye group by id