Script to generate Flat file + assign sysdate to a variable in sql script [message #403817] |
Mon, 18 May 2009 23:30 |
user71408
Messages: 585 Registered: November 2007 Location: NE
|
Senior Member |
|
|
Hi All,
I have table called EMPLOYEE. It contains Empno, Ename,Sal,JOB columns.
I want to write a shell script which generates flat file.( with two column names)
Create a flat file with the following name :
Employee_YYYYMMDD.csv
Field separator to use : " ; "
e.g. EMPNO ; ENAME
can any please help me to write a script to generate ".csv" file.
Thank you
|
|
|
|
Re: Script to generate Flat file [message #403823 is a reply to message #403820] |
Tue, 19 May 2009 00:32 |
user71408
Messages: 585 Registered: November 2007 Location: NE
|
Senior Member |
|
|
Hi ,
I have written the script as follows.
spool a.dat
select * from emp
spool off
spool b.csv
select empno||';'||ename from emp;
spool off
exit
But I need the O/P as "a_YYYYDDMM.dat" and "b_YYYYYYDDMM.csv".
But I am not getting how to append the date to the O/P file name.Can you please let me know if any mistakes in the above coding. and let me now how to add the date to the o/p file names.
Thank you
|
|
|
|
|
|
|
|
|
Re: Script to generate Flat file [message #403843 is a reply to message #403840] |
Tue, 19 May 2009 03:02 |
user71408
Messages: 585 Registered: November 2007 Location: NE
|
Senior Member |
|
|
I am working on Oracle 10g :
I am running this .sql :
set term off
set feedback off
set HEADING off
set pagesize 0
set linesize 120
set verify off
SET echo off
spool /data/dev/ins/dbi/backup/AGENT.dat
SELECT
AGENTKEY || '|' || PERSONID || '|' || ADDRESSID || '|' || AGENCYKEY || '|' || '<END_OF_RECORD>'
FROM
AGENT;
spool off
/
spool /data/dev/ins/dbi/backup/AGENCY.txt
SELECT
AGENCYKEY || '|' || SNAME || '|' || LNAME || '|' || ADDRESSID || '|' || '<END_OF_RECORD>'
FROM
AGENCY;
spool off
I have now an AGENT.dat and AGENCY.txt. How can I include the sysdate as part of the spool file ? Something like AGENT20090519.dat and AGENCY20090519.csv
|
|
|
Re: Script to generate Flat file [message #403844 is a reply to message #403843] |
Tue, 19 May 2009 03:15 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
One option : copy / move the file after it is created.
tmp # touch agent.dat
tmp # ls agent*
agent.dat
tmp # mv agent.dat agent`date '+%Y%m%d'`.dat
tmp # ls agent*
agent20090519.dat
tmp #
|
|
|
|
|
|
Re: Script to generate Flat file [message #403860 is a reply to message #403857] |
Tue, 19 May 2009 04:37 |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
Nowhere in the mentioned statement. In the shell script that calls that actual statement, after the file is created.
I guess that is headed into another user71408 classic. Something like :
"How do I get to the train station?"
"You walk down this street here, and ..."
"What is a street?"
"A street is this thing here, where the cars drive along, and ..."
"What is a car? What is driving? I just want to get to the train station!!"
"OK, then you walk in THIS DIRECTION, and ..."
"What is walking? What is a direction? I just want to get to the train station!!"
"Walking is when you put one foot before the other, and ..."
"What is a foot? I just want to get to the train station!!"
|
|
|
|
assign sysdate to a variable in sql script [message #403887 is a reply to message #403817] |
Tue, 19 May 2009 06:22 |
user71408
Messages: 585 Registered: November 2007 Location: NE
|
Senior Member |
|
|
Hi All,
I have written the following query. This query will return o/p of EMP table.The O/P shuld be stored in EMP_YYYYMMDD.dat
and the same SQL query will generate .CSV file that should be created as EMP_DET_YYYYMMDD.csv.
I need to write SQL Script for this.
select * from emp;
spool off;
select * from emp_det;
spool off;
Can any one please let me know how to assign System date to the SQL script. (Eg.. Spool EMP_(SYSTEMdate as pe rteh mentioned Format)
Thank you,
|
|
|
|
|
|
|
|
|
|
|
|
Re: Script to generate Flat file [message #404208 is a reply to message #404066] |
Wed, 20 May 2009 17:27 |
William Robertson
Messages: 1643 Registered: August 2003 Location: London, UK
|
Senior Member |
|
|
Without that filter the top hit (as usual) was a dba-oracle.com page entitled "Adding SYSDATE to a SQL*Plus spool file name" that almost gave the answer but forgot to include the "column ... new_value" line and therefore made no sense and didn't work.
|
|
|
|