create or replace function product_analyze_day_stat(p_stat_day timestamp)
returns void as $$
/**
*货品分析日报表
*/
declare
v_db_info varchar(1000) := '172.17.209.165;bi_edw;u_retail_gms';
v_function_name varchar(100) := 'product_analyze_day_stat';
v_step integer := 1;
v_start_time timestamp;
v_end_time timestamp;
v_curr_price record;
begin
--1.初始化工作
begin
if p_stat_day is null then
v_start_time := date_trunc('day',now());
v_end_time := v_start_time + interval '1 day';
else
v_start_time := date_trunc('day',p_stat_day);
v_end_time := v_start_time + interval '1 day';
end if;
--删除重复统计的数据
delete from item_analysis_report iar where iar.stat_day = v_start_time;
perform write_log(v_db_info,v_function_name,1,'初始化工作');
exception when others then
perform write_log(v_db_info,v_function_name,1,concat('初始化工作异常:',sqlerrm));
end;
postgresql 9.4存储过程示例
最新推荐文章于 2022-12-22 16:25:02 发布