现有的DWH系统的是按天创建数据表的,使得定期维护变得麻烦,例如每个月底需要将按当月产生的临时表archive。 方式1.批量生成SQL,按固定的日期值生成一堆SQL,SQL生成方法多样。但是需要确认全部sql是否正确。 方式2.编写PL/SQL function,使用游标方式批量执行。 drop function fun_datecursor(from_date text,to_date text,cond text); create or replace function fun_datecursor(from_date text,to_date text,cond text) returns text as $ declare cur_date refcursor; buffer text := ”; var_day date; begin open cur_date for execute ‘SELECT generate_series(”’|| from_date ||”’::date,”’|| to_date ||”’::date,”’|| cond ||”’)’; loop –开始循环 fetch cur_date into var_day; –将游标指定的值赋值给变量 if found then ————————————— …