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