条件:
corp money begindate enddate
1001 217 2011-04 2011-08
1002 500 2011-05 2011-07
1003 425 2011-01 2011-01
目标:
corp money dates
1001 217 2011-04
1001 217 2011-05
1001 217 2011-06
1001 217 2011-07
1001 217 2011-08
1002 500 2011-05
1002 500 2011-06
1002 500 2011-07
1003 425 2011-01
条件是目前查询出来的结果. 要求通过sql语句的方法将结果再加工成目标的样子.
紧急求教. 求各位高手解救.
我一条sql语句实现不了,用存储过程可以实现你的要求。
同求。。。
SQL> alter session set nls_date_format='yyyy-mm';
Session altered.
SQL> select * from test20110420;
CORP MONEY BEGINDA ENDDATE
1001 217 2011-04 2011-08
1002 500 2011-05 2011-07
declare
temp_date date;
begin
dbms_output.put_line('CORP'||' '||'money'||' '||'date');
for x in(select * from test20110420) loop
temp_date :=x.begindate;
while temp_date<=x.enddate loop
dbms_output.put_line(x.corp||' '||x.money||' '||temp_date);
temp_date :=add_months(temp_date,1);
end loop;
end loop;
end;
/
CORP money date
1001 217 2011-04
1001 217 2011-05
1001 217 2011-06
1001 217 2011-07
1001 217 2011-08
1002 500 2011-05
1002 500 2011-06
1002 500 2011-07