I have the following script which I am using to loop through a query and export the results in an excel file.
begin
for months in 0..12 loop
data_dump( query_in => 'select count(*) from reservation where trunc(update_date) between (select add_months(TRUNC(SYSDATE), -(months) ) from dual) and (select add_months(TRUNC(SYSDATE),-(months+1)) from dual)',
file_in => 'excel_'||months||'.csv',
directory_in => 'C:\Users\Administrator\Desktop\test',
delimiter_in => '|' );
end loop;
end;
The data_dump is a procedure that exports the results to a excel file.
I am trying to make the formula I use dynamic like below:
(select add_months(TRUNC(SYSDATE), -(months) ) from dual)
the months variable comes from the loop, but when i run the query it turns with errors.
Help with the syntax would be appreciated.