postgresql儲存過程返回值的方式有很多,在此先只記錄一下自己用到過的,慢慢拓展
1、type型,這裡geometry可以是任何postgresql支援的型別(integer/text/character varying.....)
create or replace function test(2、table型,返回資料集的一種,需要自己定義返回的字段,這裡用return query執行select返回tbl character varying)
returns geometry as
$body$
declare
v_res geometry;--最終結果
begin
return v_res;
end;
$body$
language plpgsql volatile strict
cost 100;
alter function test(character varying)
owner to postgres;
create or replace function test(3、setof table/view型,返回資料集的一種,通常是返回某錶查詢後的資料in tbl character varying)
returns table(v_gid integer, v_res geometry) as
$body$
declare
begin
--執行返回結果
return query
select v_uptap_gid as res_uptap_gid,v_uptap_geom as res_uptap_geom ;
end;
$body$
language plpgsql volatile strict
cost 100
rows 1000;
alter function test(character varying)
owner to postgres;
但是必須是表內已有字段,新增的字段不行(比如我要在返回時標識型別 'select type,a.* from tb a')
方便的地方在於不用強制定義返回字段('select * from tb' 也可以)
create or replace function test(3、setof record型,返回資料集的一種,與setof table類似in tbl character varying)
returns setof table1 as
$body$
declare
begin
select * from table1;
--或者
return query select * from table1;
end;
$body$
language plpgsql volatile strict
cost 100
rows 1000;
alter function test(character varying)
owner to postgres;
不同的是,我setof record可以返回所有字段,供呼叫的人取字段
create or replace function test(in tbl character varying)
returns setof record as
$body$
declare
r record;
begin
for r in execute 'select * from tb' loop
return next r;
end loop;
return;
end;
$body$
language plpgsql volatile strict
cost 100
rows 1000;
alter function test(character varying)
owner to postgres;
--呼叫
select * from test('tb') as member(id int, name text);
PostGIS 儲存過程返回型別
postgresql儲存過程返回值的方式有很多,在此先只記錄一下自己用到過的,慢慢拓展 1 type型,這裡geometry可以是任何postgresql支援的型別 integer text character varying.create orreplace function test tbl c...
C 執行oracle返回游標型別的儲存過程
c 執行oracle儲存過程,儲存過程 為 create or replace procedure proc test pcursor out pak pub.ut cursor as begin open pcursor for select from scott.emp end proc tes...
C 執行oracle返回游標型別的儲存過程
c 執行oracle儲存過程,儲存過程 為 create orreplace procedure proc test pcursor out pak pub.ut cursor as begin open pcursor for select from scott.emp end proc tes ...