0

我正在使用以下代码查询 oracle 数据库:

SET pagesize 0
SET linesize 250
SET wrap ON
SET colsep ,
SET trims ON
SET truncate OFF
SET FEEDBACK OFF
COLUMN col1 format a6
COLUMN col2 format a4
COLUMN col3 format 9999.999
spool /var/tmp/test.dat
SELECT /*+ parallel(8) */ 
      col1, 
      col2, 
      col3
 FROM table;
 spool off
 exit

我希望输出文件为:YYYYMMDDHHMMSS_test.dat

最好的方法是什么?

4

1 回答 1

1

试试下面的。该解决方案改编自Tom Kyte 的讨论

SET pagesize 0
SET linesize 250
SET wrap ON
SET colsep ,
SET trims ON
SET truncate OFF
SET FEEDBACK OFF
COLUMN col1 format a6
COLUMN col2 format a4
COLUMN col3 format 9999.999
SET ECHO ON
COLUMN filename new_val filename
SELECT to_char(sysdate, 'YYYYMMDDHH24MISS') || '_test.dat' filename from dual;
SPOOL &filename
SELECT /*+ parallel(8) */ 
      col1, 
      col2, 
      col3
 FROM table;
 spool off
 exit
于 2014-04-29T14:10:03.490 回答