GBase 8s
运维管理
文章

获取每个季度第一天的日期

GBase社区管理员
发表于2023-05-16 10:39:0571次浏览0个评论

create function get_q_firstd(in_time date)
returning date;

define v_in_time date;  
define cur_q int;
define rs_q_day date; 
let v_in_time=in_time;

if v_in_time is not null then
       select quarter(v_in_time) into cur_q from sysmaster:sysdual;
       if cur_q = 1   then select year(sysdate)||"-01-01" into rs_q_day from sysmaster:sysdual;
       elif cur_q = 2 then select year(sysdate)||"-04-01" into rs_q_day from sysmaster:sysdual;
       elif cur_q = 3 then select year(sysdate)||"-07-01" into rs_q_day from sysmaster:sysdual;
       elif cur_q = 4 then select year(sysdate)||"-10-01" into rs_q_day from sysmaster:sysdual;
       else
              exit;
       end if;


else
       select quarter(current) into cur_q from sysmaster:sysdual;
       if cur_q = 1   then select year(sysdate)||"-01-01" into rs_q_day from sysmaster:sysdual;
       elif cur_q = 2 then select year(sysdate)||"-04-01" into rs_q_day from sysmaster:sysdual;
       elif cur_q = 3 then select year(sysdate)||"-07-01" into rs_q_day from sysmaster:sysdual;
       elif cur_q = 4 then select year(sysdate)||"-10-01" into rs_q_day from sysmaster:sysdual;
       else
              exit;
       end if;

end if;

return rs_q_day;
end function;

评论已关闭