Store output of DB Cursor to a txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Store output of DB Cursor to a txt file
# 1  
Old 10-17-2011
Store output of DB Cursor to a txt file

I am writing a cursor to select values from 3 tables. I want to store these values in a txt file which I will be sending via ftp. I am able to store the results of simple select queries to the txt file. but I am not sure how to store the values when using a cursor. I have given the sql query below. I will be executing this in a db2 database. could someone please help me out?
Code:
FOR CRTID AS CUR1 CURSOR FOR
 SELECT CTRCTID FROM LM_ACCT_RTRVL_RQST WHERE STATUS = 'R'
DO
SELECT A.CTRCTBALAMT,                        
       A.CTRCTEFFDATE,      
       A.CUSTSTCD,  
       B.POST_DT,                       
       B.AMOUNT,                              
       B.EFF_DT,                         
       B.EXPIR_DT,
       B.TXN_TYPE_CD
  FROM  CBSAR. SCLM9973 A, CBSAR. SCLM9967 B                    
WHERE A.CTRCTID      =  CRTID.CTRCTID  AND A.CTRCTID        =   B.CTRCT_ID
END FOR;


Last edited by Franklin52; 10-17-2011 at 09:56 AM.. Reason: Please use code tags, thank you
# 2  
Old 10-17-2011
Quote:
Originally Posted by naveensraj
...I am able to store the results of simple select queries to the txt file. but I am not sure how to store the values when using a cursor. I have given the sql query below. I will be executing this in a db2 database. ...
Code:
FOR CRTID AS CUR1 CURSOR FOR
 SELECT CTRCTID FROM LM_ACCT_RTRVL_RQST WHERE STATUS = 'R'
DO
SELECT A.CTRCTBALAMT,                        
       A.CTRCTEFFDATE,      
       A.CUSTSTCD,  
       B.POST_DT,                       
       B.AMOUNT,                              
       B.EFF_DT,                         
       B.EXPIR_DT,
       B.TXN_TYPE_CD
  FROM  CBSAR. SCLM9973 A, CBSAR. SCLM9967 B                    
WHERE A.CTRCTID      =  CRTID.CTRCTID  AND A.CTRCTID        =   B.CTRCT_ID
END FOR;

Maybe you could convert the query into a simple select and save it the way you do?

Code:
SELECT A.CTRCTBALAMT,
       A.CTRCTEFFDATE,
       A.CUSTSTCD,
       B.POST_DT,
       B.AMOUNT,
       B.EFF_DT,
       B.EXPIR_DT,
       B.TXN_TYPE_CD
 FROM  CBSAR.SCLM9973 A,
       CBSAR.SCLM9967 B
       (SELECT CTRCTID
          FROM LM_ACCT_RTRVL_RQST
         WHERE STATUS = 'R'
       ) CRTID
 WHERE A.CTRCTID = CRTID.CTRCTID
   AND A.CTRCTID = B.CTRCT_ID;

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

How to store info from a txt file into a hash?

I'm trying to make a perl script using the "open" command to open and read a file, storing the information in said file into a hash structure. This is what is inside my file- Celena Standard F 01/24/94 Cancer Jeniffer Orlowski F 06/24/86 None Brent Koehler M 12/05/97 HIV Mao Schleich... (4 Replies)
Discussion started by: Eric1
4 Replies

2. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

3. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

4. Shell Programming and Scripting

Need to convert output.txt into html file

I have output.txt file generated through shell scripts which need convert in tabular format using html can you please help me output.txt Token State Date1 Date2 Description Name 34567 open 27/06/13 28/06/13 ... (5 Replies)
Discussion started by: vijay_rajni
5 Replies

5. UNIX for Advanced & Expert Users

Help on Shell Scripting - to store output to a fixed file

Hi I have a file called "test.txt" and it looks like this x y z x/c y/c/b now, i want to run a command and its output will be like this x 10 y/c/b 20 z 78 -------- my requirement is, i want to add the command output to "test.txt" as like below x 10 y ... (1 Reply)
Discussion started by: siva kumar
1 Replies

6. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

7. Homework & Coursework Questions

man command output to a txt file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to outut the man command output into a text file which will help me for future reference. 2.... (8 Replies)
Discussion started by: hariniiyer300
8 Replies

8. Shell Programming and Scripting

Store grep output file

Hi, I'm trying to store the output from a grep, I just want the file name. But couldn't find how to do it. Basically, I just want to grep <etc> * and I want to store the file name. There is only one file with the what I'm grepping, so storing in a variable o an array its the same. If someone... (3 Replies)
Discussion started by: radicaled
3 Replies

9. Shell Programming and Scripting

How to store the sql query output into txt file?

Hi I want ot save SQL query result in one txt file. for that i have written one code line sqlplus -s $dbstring @/usr/local/bin/sched/nightly_Cronjob/exec_123.sql >> /usr/local/bin/sched/nightly_Cronjob/result.txt but it is not working . database : Oracle so please advice me how can i... (7 Replies)
Discussion started by: Himanshu_soni
7 Replies

10. Shell Programming and Scripting

store output to a file and read from it

Hello all, I need to run snoop command for a period of time (a day) and extract remote host column from it to find out who is accessing my server. When I run the following on the command line it works snoop -port 22 | awk '{print $3}' but when I do snoop -port 22 | awk '{print $3}' | while... (2 Replies)
Discussion started by: afadaghi
2 Replies
Login or Register to Ask a Question