Use Spoll to save query to a file : spool « SQL PLUS Session Environment « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> set linesize 500
SQL> set trimspool on
SQL> set embedded on
SQL> spool logmnr.opt
SQL> select
  2      'colmap = ' || user || ' ' || table_name || ' (' ||
  3     max( decode( column_id, 1,       column_id  , null ) ) ||
  4     max( decode( column_id, 1, ', '||column_name, null ) ) ||
  5     max( decode( column_id, 2, ', '||column_id  , null ) ) ||
  6     max( decode( column_id, 2, ', '||column_name, null ) ) ||
  7     max( decode( column_id, 3, ', '||column_id  , null ) ) ||
  8     max( decode( column_id, 3, ', '||column_name, null ) ) ||
  9     max( decode( column_id, 4, ', '||column_id  , null ) ) ||
 10     max( decode( column_id, 4, ', '||column_name, null ) ) ||
 11     max( decode( column_id, 5, ', '||column_id  , null ) ) ||
 12     max( decode( column_id, 5, ', '||column_name, null ) ) || ');' colmap
 13   from user_tab_columns
 14  group by user, table_name
 15  /
COLMAP
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
colmap = JAVA2S AVAIL_TRACE_FILES (1, USERNAME, 2, FILENAME, 3, DT);

COLMAP
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
colmap = JAVA2S INTEREST (1, YR, 2, RATE);
colmap = JAVA2S AUTHOR_PUBLICATION (1, ID, 2, NAME, 3, TITLE, 4, WRITTEN_DATE);
colmap = JAVA2S DEPT_OR (1, DEPTNO, 2, DNAME, 3, LOC, 4, EMPS);
colmap = JAVA2S BIN$z+/2/T9WTRWmOfXZhvGBPQ==$0 (1, ID, 2, WORKER_ID, 3, LOGICAL_WORKPLACE_ID, 4, ACTIVE_DATE, 5, INACTIVE_DATE);
colmap = JAVA2S HOME_ADDRESS_LIST (1, LIST_ID, 2, HOME_ADDRESSES);
colmap = JAVA2S MYCLOB (1, ID, 2, CLOB_DATA);
colmap = JAVA2S CRS_OFFERINGS (1, COURSE_CODE, 2, DESCRIPTION, 3, BEGINDATE);
colmap = JAVA2S BIN$2AYTRnCPRfG80DYlHN4sJg==$0 (1, ID, 2, WORKER_ID, 3, LOGICAL_WORKPLACE_ID, 4, ACTIVE_DATE, 5, INACTIVE_DATE);
colmap = JAVA2S HRC_ORG_SITE (1, HRC_CODE, 2, HRC_DESCR, 3, ORG_ID, 4, ORG_SHORT_NAME, 5, ORG_LONG_NAME);
colmap = JAVA2S EMPLOYEE_EMPLOYEE_EVALUATION (1, ID, 2, NAME, 3, TITLE, 4, WRITTEN_DATE);
colmap = JAVA2S EMPLOYEE_EVALUATION (1, ID, 2, TITLE, 3, WRITTEN_DATE);

COLMAP
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
colmap = JAVA2S I2 (1, N, 2, V);
colmap = JAVA2S DEPT20_V (1, EMPNO, 2, ENAME, 3, INIT, 4, JOB, 5, MGR);
colmap = JAVA2S USER_AVAIL_TRACE_FILES (1, USERNAME, 2, FILENAME, 3, DT);
colmap = JAVA2S T1_TIMES (1, XSTART, 2, XSTOP);
colmap = JAVA2S WORKING_CUSTOMERS (1, CUST_NO, 2, LASTNAME, 3, FIRSTNAME, 4, MIDINIT, 5, STREET);
colmap = JAVA2S STUDENT (1, STUDENT_ID, 2, PERFORMANCE, 3, GENDER, 4, ETHNICITY, 5, AGE);
colmap = JAVA2S WORKING_EMPLOYEES (1, EMPL_NO, 2, LASTNAME, 3, FIRSTNAME, 4, MIDINIT, 5, STREET);
colmap = JAVA2S EMP_V (1, EMPNO, 2, ENAME, 3, JOB, 4, MGR, 5, SAL);
colmap = JAVA2S BIN$BIALfQCESHa/SipQl+oqGg==$0 (1, ID, 2, WORKER_ID, 3, LOGICAL_WORKPLACE_ID, 4, ACTIVE_DATE, 5, INACTIVE_DATE);
colmap = JAVA2S COURSE_DAYS (1, EMPNO, 2, ENAME, 3, DAYS);
colmap = JAVA2S HAZARD_LEVEL_T (1, ID, 2, MAGNITUDE, 3, CODE, 4, DESCRIPTION, 5, ACTIVE_DATE);

COLMAP
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
colmap = JAVA2S EMP_VIEW (1, ENAME, 2, EMPNO);
colmap = JAVA2S DDL_AUDIT (1, OBJECT_NAME, 2, OBJECT_TYPE, 3, WHEN_CREATED, 4, WHO_CREATED, 5, WHEN_UPDATED);
colmap = JAVA2S MYTABLE1_TIMES (1, XSTART, 2, XSTOP);
colmap = JAVA2S I1 (1, N, 2, V);
colmap = JAVA2S CRS_COURSE_SCHEDULE (1, COURSE_CODE, 2, DESCRIPTION, 3, BEGINDATE);
colmap = JAVA2S EMPLOYEE_PUBLICATION (1, ID, 2, NAME, 3, TITLE, 4, WRITTEN_DATE);
colmap = JAVA2S SALES_BY_ATLAS_V (1, PRODUCT_NAME, 2, SALESPERSON, 3, ORDER_DATE, 4, QUANTITY);
colmap = JAVA2S SALES_PER_PERSON_V (1, SALESPERSON, 2, PRODUCT_NAME, 3, ORDER_DATE, 4, QUANTITY);
colmap = JAVA2S AVG_EVALUATIONS (1, COURSE, 2, AVG_EVAL);
colmap = JAVA2S APPLICATION_USERS (1, UNAME, 2, PW, 3, ROLE_TO_GRANT);
colmap = JAVA2S SITE_TAB (1, SITE_NO, 2, SITE_DESCR);

COLMAP
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
colmap = JAVA2S OUTRAIN (1, DY, 2, RAINFALL);
colmap = JAVA2S DUMMY (1, COL1);
colmap = JAVA2S BIN$uR9LzoavTbyjK4b4t8kgXg==$0 (1, ID, 2, WORKER_ID, 3, PHYSICAL_WORKPLACE_ID, 4, ACTIVE_DATE, 5, INACTIVE_DATE);
colmap = JAVA2S BIN$ukEn3nqRT+u/paBe8fJpxQ==$0 (1, ID, 2, WORKER_ID, 3, LOGICAL_WORKPLACE_ID, 4, ACTIVE_DATE, 5, INACTIVE_DATE);
colmap = JAVA2S MAP (1, N, 2, I1, 3, I2);
colmap = JAVA2S EMP_DEPT_CLUSTER (1, DEPTNO);
colmap = JAVA2S HASH_CLUSTER (1, HASH_KEY);

41 rows selected.

SQL> spool off
SQL>








29.55.spool
29.55.1.Use Spoll to save query to a file
29.55.2.Spool to a file with compute
29.55.3.Spool result to a text file
29.55.4.Extracts data from the emp table and writes it to a text file in a comma-delimited format