PostgreSQL自定义函数返回单条记录类型的例子...

前端之家收集整理的这篇文章主要介绍了PostgreSQL自定义函数返回单条记录类型的例子...前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CREATE OR REPLACE  function fun_getRecSeq_range(p_dt timestamp) returns record 
as 
$BODY$
declare c_str varchar;
declare ret record;
begin
   c_str:='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$.`';
   select (substr(c_str,extract(YEAR from p_dt)::int-2010+1,1)||
   substr(c_str,extract(month from p_dt)::int+1,extract(day from p_dt)::int+1,1) )::varchar as seqStart,(substr(c_str,1)||'ZZZZ')::varchar as seqEnd
   into ret ;      
   return ret ;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
  COST 100;

  select * from fun_getRecSeq_range(current_date) as (seqStart varchar,seqEnd varchar)


上面例子将日期转为recseq的范围,单条记录的,若要用多条记录,要用set of record ...

原文链接:https://www.f2er.com/postgresql/194960.html

猜你在找的Postgre SQL相关文章