Oracle 循环查询并将结果导出到excel的脚本
我使用以下脚本循环查询并将结果导出到excel文件中Oracle 循环查询并将结果导出到excel的脚本,oracle,plsql,Oracle,Plsql,我使用以下脚本循环查询并将结果导出到excel文件中 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(TRUN
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;
数据转储是将结果导出到excel文件的过程
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;
我试图使我使用的公式动态如下:
(select add_months(TRUNC(SYSDATE), -(months) ) from dual)
months
变量来自循环,但当我运行查询时,它会出错
如果您能提供语法方面的帮助,我们将不胜感激。我认为问题在于:
'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)'
在你的例子中,“月”只是文本。您需要以这种方式更改表达式:
'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)'
我认为问题在于:
'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)'
在你的例子中,“月”只是文本。您需要以这种方式更改表达式:
'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)'
尝试像“| |月| | |”这样的月份动态获取值尝试像“| |月| |”这样的月份动态获取值请提供错误。请提供错误。