質問

I'm querying an oracle database with the following code:

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

I want the output file to be: YYYYMMDDHHMMSS_test.dat

What's the best to do this?

役に立ちましたか?

解決

Try the following. The solution has been adapted from Tom Kyte's discussion.

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top