在plpgsql函数中返回结果集

Posted in Database by neemem on 08-20-2008.

类型只是一个虚拟的东西,它并没有实际的存储空间,因此结果集合的返回一定要依靠一种实在的表的结构,你或者在定义
函数时候返回一个表或者视图或者象下面的例子一样在调用函数的时候
后面跟着一个表的结构。

说明:表和视图创建成功以后在的类型系统表中会自动增加
以他们的名字命名的类型),也就是说某个表和某个视图其实也是一
种数据类型。

create table mm(a int, b int);
 into mm (1,1);
 into mm (2,2);
 into mm (3,3);

create or replace  mmm() returns setof  as

declare
rec ;
begin

FOR rec IN SELECT * FROM mm LOOP
RETURN NEXT rec;
END LOOP;
end;’language ’’;

select a.a,a.b from mmm() a(a int, b int);

a | b
—+—
1 | 1
2 | 2
3 | 3

Related posts:
苹果的App分享5亿美元的软件销售市场 pgsql install python

2 Responses to “在plpgsql函数中返回结果集”

» You can leave a response or Trackback .

  1. Php5 Pgsql Says:

    I found your site on faves.com bookmarking site.. I like it ..gave it a fave for you..ill be checking back later

    [Reply]

    neemem Reply:

    oo…..thks

    [Reply]

» Trackbacks/Pingbacks

Leave a Reply