set echo off
set feedback off
set newpage none
set pagesize 5000
set linesize 500
set verify off
set pagesize 0
set term off
set trims on
set linesize 600
set heading off
set timing off
set verify off
set numwidth 38
SPOOL c:\drop_table.sql
select DEPTNO || '','' || DNAME FROM DEPT;
SPOOL OFF
将上面的内容保存为一个文本文件后,以scott登录,执行该文件后显示结果:
10,ACCOUNTING
20,RESEARCH
30,SALES
40,OPERATIONS
通过上面的两个例子,我们可以将:
set echo off
set feedback off
set newpage none
set pagesize 5000
set linesize 500
set verify off
set pagesize 0
set term off
set trims on
set linesize 600
set heading off
set timing off
set verify off
set numwidth 38
SPOOL c:\具体的文件名
你要运行的sql语句
SPOOL OFF
作为一个模版,只要将必要的语句假如这个模版就可以了。
在oracle的较新版本中,还可以用set colsep命令来实现上面的功能:
SQL> set colsep ,
SQL> select * from dept;
10,ACCOUNTING ,NEW YORK
20,RESEARCH ,DALLAS
30,SALES ,CHICAGO
40,OPERATIONS ,BOSTON
35,aa ,bb