Reading data from DataBase and Writing to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading data from DataBase and Writing to a file
# 1  
Old 11-09-2009
Reading data from DataBase and Writing to a file

Hi All,

Please help me in writing data to a file in one row.

In database there is a column which contains large data which does not fit in the file in one row. The column contains list of paths. I want to write these paths to a file in one row.

Please find the code below writes :

Code:
sqlplus -s $DBCredentials  1> $myJobTaskAttribListFile   <<-EndOFSQL
 SET DEFINE OFF;
 SET SERVEROUT ON
 SET LINESIZE 3400;
 DECLARE
  i_job_id      NUMBER := $myJobId ;
  o_run_status_id    NUMBER := 0 ;
  i_end_time          VARCHAR2(1000) ;
  i_total_errors      NUMBER := 0 ;
  i_total_warnings    VARCHAR2(1000) ;
  i_total_inserted    NUMBER := 0 ;
  i_total_updated     NUMBER := 0 ;
  i_total_rejected    NUMBER := 0 ;
  i_log_file          VARCHAR2(1000) ;
  i_job_run_message   VARCHAR2(512) ;
  i_modlast_by        VARCHAR2(1000) ;
  o_sqlcode          NUMBER := 0 ;
  o_sqlmsg       VARCHAR2(1000) ;
 BEGIN
  $myUSPLoadJobTaskAttribs
  (
   i_job_id,
   o_run_status_id,
   o_sqlcode,
   o_sqlmsg 
  );
  
 END; 
 /
 EndOFSQL

I am getting Output as fallows..

Code:
1=XP|classpath|/usr/home/dfusr/lib/xalan.jar:
/usr/home/dfusr/lib/xerces.jar:
/usr/home/dfusr/lib/xml.jar:
/usr/home/dfusr/lib/classes12.zip:
/usr/home/dfusr/lib/DataFeed.jar:
/usr/home/dfusr/lib/pedf/MeetingAlertEmail.jar:
/usr/home/dfusr/lib/mailapi.jar:
/usr/home/dfusr/lib/pop3.jar:
/usr/home/dfusr/lib/activation.jar:
/usr/home/dfusr/lib/smtp.jar:
/usr/home/dfusr/lib/ADPModel.jar:
/usr/home/dfusr/lib/ADPUtil.jar:
/usr/home/dfusr/lib/ServiceLocator.jar:
/usr/home/dfusr/lib/log4j-1.2.8.jar:
/usr/home/dfusr/lib/toplink.jar:
/usr/home/dfusr/lib/xmlparserv2.jar

I want to write all the paths (at max 20) in one row as fallows.

Code:
1=Java|classpath|/usr/home/dfusr/lib/xalan.jar:/usr/home/dfusr/lib/xerces.jar:/usr/home/dfusr/lib/xmlparserv2.jar

Please help me in this regards

I set the LINESIZE of 3400 as above under sql but it not working


Thanks-
Rajesh

Last edited by Franklin52; 11-09-2009 at 07:44 AM.. Reason: Please use code tags!!
# 2  
Old 11-09-2009
after you got the output , pipe line this to

Code:
cat file_name | tr '\n' ' '

# 3  
Old 11-09-2009
Alternatively, you could tweak your SQL query to print all those values as a delimited string.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading and writing in same file

Hi All, Here is my requirement. I am grepping through the log files and cutting some fields from the file to generate a csv file. Now I have to check if 2nd field is having some fixed value then with the help of 4th field I have to look in same log and run another grep command to retrieve the... (11 Replies)
Discussion started by: kmajumder
11 Replies

2. UNIX for Dummies Questions & Answers

Reading and writing data to and from multiple files

Hi, I have several text files. One main file contains the detail data, other have some information to extract data from the main file, and some are empty files. Examples are shown below: The main file look like: MainFile.txt >Header1 data1...data1... >Header2 data2...data2... ... ...... (2 Replies)
Discussion started by: Fahmida
2 Replies

3. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

4. Programming

I need help with file reading/writing in C

Hello everybody, I'm trying to code a program which makes the following: It sends an ARP request frame and when it gets the reply, extracts the IP address of source and writes it to a .txt file. This is gonna be done with many hosts (with a for() loop), so, the text file would look like... (2 Replies)
Discussion started by: Zykl0n-B
2 Replies

5. UNIX for Dummies Questions & Answers

Log File Writing and Reading

Hi all, I have the following shell script code which tries to sftp and writes the log into the log file. TestConnection () { echo 'Connection to ' $DESTUSERNAME@$DESTHOSTNAME $SETDEBUG if ]; then rm $SCRIPT ; fi touch $SCRIPT echo "cd" $REMOTEDIR >> $SCRIPT echo "quit" >>... (10 Replies)
Discussion started by: valluvan
10 Replies

6. Shell Programming and Scripting

how to insert data into database by reading it from a text file??

Hi....can you guys help me out in this script?? Below is a text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (4 Replies)
Discussion started by: pallavishetty
4 Replies

7. UNIX for Dummies Questions & Answers

reading ,writing,appending ,manipulating a file.

Hi my prob statement is to create a new file or to append to the 1tst file the followign chages. File 1: txt file. portfolio No a b c d abc 1 Any Any Any charString cds 2 values values values charString efd 3 can can can charString fdg 4 come come come charString... (4 Replies)
Discussion started by: szchmaltz
4 Replies

8. Shell Programming and Scripting

writing script file for database

how to disable a constraint type of a field (present in diffrent tables) in the database unix a unix script file.. (3 Replies)
Discussion started by: shaksing
3 Replies

9. Programming

Reading and Writing file on LAN

Hi gurus I am not a C programmer but I need to read and write files on a computer on LAN using IP address. Suppose on a computer that has an IP 192.168.0.2 Any help or code example. I did in JAVA using URL, but do not know how to do in ANSI-C. In java: ------- URL url = new... (3 Replies)
Discussion started by: lucky001
3 Replies

10. UNIX for Advanced & Expert Users

writing database tables into a file in unix

I want to collect the database tables(Ex: Emp,Sal,Bonus...etc) in a file & give this file at the command prompt, when prompted for the tables list at command prompt. How can i do that ? Ex:- Import jason/jason1 tables=emp,sal,bonus log=j1.log i want to change this into Ex:- Import... (3 Replies)
Discussion started by: dreams5617
3 Replies
Login or Register to Ask a Question