Wednesday, February 25, 2009

Oracle spool

Example1 :
Spool data from oracle to text file also you can add title to the text file .


set linesize 50;
set echo off;
set pagesize 9999;
set newpage none;
set heading on;
set recsep off;

spool c:\Data\FileName.txt ;

TTITLE left 'BEX Approved Batch sheets'; -- /* Add title to the text file*/
column c1 heading "emp_id" format a5
column c2 heading "emp_name" format a25
column c3 heading "emp_salary" format $9,999,990.99

SELECT emp_id c1,
emp_name c2,
emp_salary c3
From employee where (emp_salary >=60000)
spool off;

Example 2:
Spool data from oracle to text file and name the file with date and time of data spool

set linesize 50;
set echo off;
set pagesize 9999;
set newpage none;
set heading on;
set recsep off;

col sys_date new_value curr_date;
select 'c:\data\'to_char(sysdate,'yyyy_ddmon_hh24_miss')'.txt' sys_date from dual;
spool &curr_date;

column c1 heading "emp_id" format a5
column c2 heading "emp_name" format a25
column c3 heading "emp_salary" format $9,999,990.99

SELECT emp_id c1,
emp_name c2,
emp_salary c3
From employee where (emp_salary >=60000)
spool off;

No comments:

Post a Comment