Примерно так:
- сначала выберите заголовки,
- , затем остальные данные - до этого выберите,
set pagesize 0
Недостатокявляется пустой строкой (которая содержит только разделители). Я не знаю, как от этого избавиться.
Вот, пожалуйста:
p.sql
-- general settings
set termout off
set feedback off
set colsep ';'
-- headings
col empno format a10
col ename format a10
col salary format a10
spool emps.txt
select null as empno, null as ename, null as salary from dual;
-- data
set pagesize 0
col empno format 99999
col ename format a10
col salary format 999G990
select empno, ename, sal from emp;
spool off
Вызов сценария:
c:\Temp>sqlplus scott/tiger
SQL*Plus: Release 11.2.0.2.0 Production on ╚et Lis 24 19:31:38 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> @p
SQL>
Результат:
EMPNO ;ENAME ;SALARY
----------;----------;----------
; ; --> this is line I'm talking about
7369;SMITH ; 800
7499;ALLEN ; 1600
7521;WARD ; 1250
7566;JONES ; 2975
7654;MARTIN ; 1250
7698;BLAKE ; 2850
7782;CLARK ; 2450
7788;SCOTT ; 3000
7839;KING ; 5000
7844;TURNER ; 1500
7876;ADAMS ; 1100
7900;JAMES ; 950
7902;FORD ; 3000
7934;MILLER ; 1300