plpgsql 函数定义

 1 --Function: dbo.fn_test(integer)
 2 
 3 --DROP FUNCTION dbo.fn_test(integer);
 4 
 5 CREATE OR REPLACE FUNCTION dbo.fn_test
 6 (
 7   IN  p_count  integer = 0
 8 )
 9 RETURNS TABLE 
10 (
11   id   integer,
12   des  text
13 )
14 AS
15 $$
16 declare
17   i integer; 
18   top integer; 
19   rec record;
20 begin
21   /* Insert real code here */
22   select into rec * from dbo.a_org_type order by id desc limit 1;
23   i := rec.id + 1;
24   top := i + p_count;
25   
26   while i < top loop
27     insert into dbo.a_org_type(id, des) 
28     values(i, 'shang hai ' || i);
29     i:= i+1;
30   end loop;
31   
32   return query select * from dbo.a_org_type order by id desc limit 10;
33 end;
34 $$
35 LANGUAGE 'plpgsql';
36 
37 ALTER FUNCTION dbo.fn_test(integer)
38   OWNER TO postgres;

 

posted on 2018-04-05 22:47  jonney_wang  阅读(799)  评论(0编辑  收藏  举报

导航