把一个表按照时间不同分成N张表解决办法
把一个表按照时间不同分成N张表
db1数据库 db2数据库
A表(a,b,c,d,t) t是时间, A1表(a,c,d,b,t) t 是XX年1月
A2表(a,c,d,b,t) t 是XX年2月
......
求存储过程
------解决方案--------------------
db1数据库 db2数据库
A表(a,b,c,d,t) t是时间, A1表(a,c,d,b,t) t 是XX年1月
A2表(a,c,d,b,t) t 是XX年2月
......
求存储过程
------解决方案--------------------
- SQL code
begin for rec in(select distinct trunc(t,'mm') logdate from a) loop execute immediate 'create table A'|| to_char(rec.logdate,'yyyymm') ||' as select * from A where A.t >= ' ||'to_date(''' || to_char(rec.logdate,'yyyy-mm') ||''',''yyyy-mm'')' ||' and A.t < ' ||' to_date(''' || to_char(add_months(rec.logdate,1),'yyyy-mm') ||''',''yyyy-mm'')' || ';'; end loop; end;