我有一个SQL脚本,它将数据假脱机到一个文件。 示例现有SQL脚本:
whenever sqlerror exit failure rollback
spool test.txt
set serveroutput on
select * from emp;
spool off
/
但是,我想在假脱机数据之前在这个脚本中编写一个SQL查询。 我不想硬编码假脱机文件的名称,那么如何从表或查找中获取文件名?
我希望代码类似于
var filename varchar2(30);
select fname into :filename from table where script = 'abcscript';
spool :filename
set serveroutput on
select * from emp;
spool off
/
感谢。
答案 0 :(得分:3)
COLUMN spool_file_name NEW_VALUE.spool_file_name NOPRINT
select fname spool_file_name
from table where script = 'abcscript';
SPOOL &spool_file_name
SET ECHO ON
select * from emp ;
SPOOL OFF
COLUMN spool_file_name CLEAR