postgreSql自定义函数

创建自定义 函数

CREATE OR REPLACE FUNCTION zfunc_test(int4,varchar)

  RETURNS "varchar" AS
$BODY$
DECLARE
v_retval varchar;
v_length integer;
BEGIN
v_length = $1;
v_retval :=''||v_length||'wang'||$2;
return v_retval;
END;
$BODY$

  LANGUAGE 'plpgsql' VOLATILE;

ALTER FUNCTION zfunc_test(int4) OWNER TO postgres;


测试

select zfunc_test(2,'yong')


create or replace function testtale1(varchar)
returns table(name text)
as
$$
begin
   RETURN QUERY select regexp_split_to_table('hello,world',',');
end
$$
language 'plpgsql'


select testtale1('hello,world')


select regexp_split_to_table('hello,world',',') as name


posted @ 2014-05-24 18:31  王永华  阅读(4447)  评论(0编辑  收藏  举报