2014-04-29 23 views
0

日期時間,我查詢用下面的代碼Oracle數據庫:入門在SQL

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

什麼是最好做到這一點?

+0

檢查了這一點 - https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3581757800346555562 –

回答

1

請嘗試以下操作。該解決方案已從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