Extract records from Oracle to UNIX file with headers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract records from Oracle to UNIX file with headers
# 1  
Old 05-03-2013
Extract records from Oracle to UNIX file with headers

Hi,

I have a shell script which extracts records form oracle to unix file.


Code:
 
sqlplus -s ${WMD_DM_CONNECT} <<EOF >$tmpfile
set heading off
set pagesize 0
set feedback off
select CD_DESC||'|'||CD_ID||'|'||'Arun'||'|'||'Montu'  from WMD_SYS_CD_LKUP
where CD_TYP = 'FILE_VLDTN_ERROR_CD';
exit
EOF

I want the headers also in the file. That too pipe delimited. Is there a way?

Any help appreciated..
Thanks in advance
# 2  
Old 05-03-2013
I guess set heading on would print the headers. You know you can set the field/column separator to |, so you don't need that intricate select statement?
# 3  
Old 05-03-2013
Yes i used the below query to get output:

Code:
sqlplus -s ${WMD_DM_CONNECT} <<EOF>arun_temp.out
set feedback off
set colsep |
select proc_id ,FILE_ID,FILE_DT,STAT_CD from wmd_file_cntl where rownum < 10;
exit
EOF


HTML Code:
   PROC_ID|   FILE_ID|FILE_DT  |   STAT_CD
----------|----------|---------|----------
         2|         1|24-NOV-12|         3
         3|         1|24-NOV-12|         3
         4|         1|24-NOV-12|         3
         5|         1|24-NOV-12|         3
         6|         1|24-NOV-12|         3
         7|         1|24-NOV-12|         3
         8|         1|24-NOV-12|         2
         9|         1|24-NOV-12|         3
        18|         1|24-NOV-12|         2
But the data doesnt look good to me as pipe delimited data should be like the blow:

HTML Code:
PROC_ID|FILE_ID|FILE_DT|STAT_CD
2|1|24-NOV-12|3
3|1|24-NOV-12|3
4|1|24-NOV-12|3
5|1|24-NOV-12|3
6|1|24-NOV-12|3
7|1|24-NOV-12|3
8|1|24-NOV-12|2
9|1|24-NOV-12|3
8|1|24-NOV-12|2
Can you suggest what i am doing wrong here?
# 4  
Old 05-03-2013
If I recall correctly - forgive me, my Oracle experience is a bit rusty - you can also set an indentation or alignment option ? If not, you need to remove the whitespace with awk or sed.
# 5  
Old 05-03-2013
Quote:
Originally Posted by RudiC
If I recall correctly - forgive me, my Oracle experience is a bit rusty - you can also set an indentation or alignment option ? If not, you need to remove the whitespace with awk or sed.
One ca set the column format however it might again endup with wrong headers

Ex:
Code:
 
column a format a20
column b format a20

I guess still the concat option holds good. if one want header input a dummy header selection from dual table before actual select staement and keep header off.
# 6  
Old 05-28-2013
try this

Code:
sqlplus -s ${WMD_DM_CONNECT} <<EOF >$tmpfile set heading off set pagesize 0 set feedback off
dbms_output.put_line('EMPLID'||'|'||'EMPL_RCD'||'|'||'Arun'||'|'||'Mountu');
select CD_DESC||'|'||CD_ID||'|'||'Arun'||'|'||'Montu'  from WMD_SYS_CD_LKUP where CD_TYP = 'FILE_VLDTN_ERROR_CD'; exit EOF


Last edited by Scott; 05-28-2013 at 04:35 AM.. Reason: Code tags PLEASE...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Needed: UNIX shell variables to store Oracle table records

Hello Folks, I'm working on a requirement to automate the process of generating report(csv file) using metadata info stored in an Oracle table and E-mail it to respective people. Meta data table: Report_ID,Report_SUB_ID,Report_DB,Report_SQL,Report_to_email_Id 1,1,DEV,'select * From... (2 Replies)
Discussion started by: venkat_reddy
2 Replies

2. Shell Programming and Scripting

Extract UNIque records from File

Hi, I have a file with 20GB Pipe Delimited file where i have too many duplicate records. I need an awk script to extract the unique records from the file and put it into another file. Kindly help. Thanks, Arun (1 Reply)
Discussion started by: Arun Mishra
1 Replies

3. Shell Programming and Scripting

Extract error records based on specific criteria from Unix file

Hi, I look for a awk one liner for below issue. input file ABC 1234 abc 12345 ABC 4567 678 XYZ xyz ght 678 ABC 787 yyuu ABC 789 7890 777 zxr hyip hyu mno uii 678 776 ABC ty7 888 All lines should be started with ABC as first field. If a record has another value for 1st... (7 Replies)
Discussion started by: ratheesh2011
7 Replies

4. Shell Programming and Scripting

ksh coding to extract records from file

Hello, I have a file with various records in it (from length 30 - 195) and I want to run a script to read each line and copy only the recl=80 files to an output file. Any help much appreciated (4 Replies)
Discussion started by: Grueben
4 Replies

5. Shell Programming and Scripting

Extract file records based on some field conditions

Hello Friends, I have a file(InputFile.csv) with the following columns(the columns are pipe-delimited): ColA|ColB|ColC|ColD|ColE|ColF Now for this file, I have to get those records which fulfil the following condition: If "ColB" is NOT NULL and "ColD" has values one of the following... (9 Replies)
Discussion started by: mehimadri
9 Replies

6. UNIX for Dummies Questions & Answers

Extract records by column value - file non-delimited

the data in my file is has no delimiters. it looks like this: H52082320024740010PH333200612290000930 0.0020080131 D5208232002474000120070306200703060580T1502 TT 1.00 H52082320029180003PH333200702150001 30 100.0020080205 D5208232002918000120070726200707260580T1502 ... (3 Replies)
Discussion started by: jclanc8
3 Replies

7. Shell Programming and Scripting

Merging of files with different headers to make combined headers file

Hi , I have a typical situation. I have 4 files and with different headers (number of headers is varible ). I need to make such a merged file which will have headers combined from all files (comman coluns should appear once only). For example - File 1 H1|H2|H3|H4 11|12|13|14 21|22|23|23... (1 Reply)
Discussion started by: marut_ashu
1 Replies

8. Shell Programming and Scripting

Extract data from large file 80+ million records

Hello, I have got one file with more than 120+ million records(35 GB in size). I have to extract some relevant data from file based on some parameter and generate other output file. What will be the besat and fastest way to extract the ne file. sample file format :--... (2 Replies)
Discussion started by: learner16s
2 Replies

9. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies

10. UNIX for Advanced & Expert Users

Duplicate records from oracle to text file.

Hi, I want to fetch duplicate records from an external table to a text file. Pls suggest me. Thanks (1 Reply)
Discussion started by: shilendrajadon
1 Replies
Login or Register to Ask a Question