postgresql儲存過程返回值的方式有很多,在此先只記錄一下自己用到過的,慢慢拓展
1、type型,這裡geometry可以是任何postgresql支援的型別(integer/text/character varying.....)
createorreplace
function
test(
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;
2、table型,返回資料集的一種,需要自己定義返回的字段,這裡用return query執行select返回
createorreplace
function
test(
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
100rows
1000
;alter
function test(character
varying
) owner
to postgres;
3、setof table/view型,返回資料集的一種,通常是返回某錶查詢後的資料
但是必須是表內已有字段,新增的字段不行(比如我要在返回時標識型別 'select type,a.* from tb a')
方便的地方在於不用強制定義返回字段('select * from tb' 也可以)
createorreplace
function
test(
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
100rows
1000
;alter
function test(character
varying
) owner
to postgres;
3、setof record型,返回資料集的一種,與setof table類似
不同的是,我setof record可以返回所有字段,供呼叫的人取字段
createorreplace
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;
endloop;
return
;end
; $body$
language plpgsql volatile strict
cost
100rows
1000
;alter
function test(character
varying
) owner
topostgres;
--呼叫
select
*from test('
tb') as member(id int, name text);
PostGIS 儲存過程返回型別
postgresql儲存過程返回值的方式有很多,在此先只記錄一下自己用到過的,慢慢拓展 1 type型,這裡geometry可以是任何postgresql支援的型別 integer text character varying.create or replace function test tbl ...
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 ...