Solved

UTL_FILE.PUT_LINE getting records on one row...

Posted on 2008-10-28
5
1,187 Views
Last Modified: 2013-12-19
I'm using UTL_FILE.PUT_LINE and I either get the last record only or I get all of the records on one row instead of one row for each record.  See example:
v_piece := v_id_number  || CHR(9) ||
                  v_label_name_line2  || CHR(9) ||

UTL_FILE.PUT_LINE(
                                 v_div_writer,
                                 v_piece,
                                 TRUE
                                );

What am I doing wrong?  (I am a beginner, sorry).
0
Comment
Question by:fprickett
  • 3
  • 2
5 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 22826058
can you post all of your code?  or at least a more complete snippet?
Something that shows how you are pulling the data into your variables.


You've described two different symptoms, please post the corresponding code for each symptom
as well as what it you are expecting the output to be.
0
 

Author Comment

by:fprickett
ID: 22826338
How's this?  (larger code sample)

    -- Opening the Outer Cursor --
    OPEN online_report_cursor;
      
    -- Fetching the first value from the Outer Cursor --
    FETCH
      online_report_cursor
    INTO
      v_id_number,
        v_label_name_line1,
        v_label_name_line2,
        v_pref_street1,
        v_pref_street2,
        v_pref_street3,
        v_pref_city_state_zip,
        v_pledge_amount,
        v_pledge_date_of_record,
        v_alloc_long_name,
        v_pledge_amt_paid,
        v_pledge_pay_amt,
        v_pledge_type_desc,
        v_division;
      
    -- Looping through the Outer Cursor --      
    WHILE online_report_cursor%FOUND LOOP  
     

        v_balance_due :=  v_pledge_amount - v_pledge_amt_paid;  

                       v_payments_remaining := ROUND(v_balance_due / v_pledge_pay_amt,2);
        
        v_months_remaining := v_payments_remaining / 2;

                       IF v_months_remaining <= 2 THEN
        
             
        
    v_div_file_name := 'PP_' || v_division ||'_' || v_file_week || '.xls';        -- in MMDDYYYY format --

          -- Is the file writer open? --
          IF UTL_FILE.IS_OPEN(v_div_writer) THEN
            -- If so, close it --
            UTL_FILE.FCLOSE(v_div_writer);
            END IF;       
        

          -- Opening the file for writing --  
        v_div_writer := UTL_FILE.FOPEN(
                                               FTP_FROM_DIR,
                                v_div_file_name,
                                                           'w',
                                               32767                                                      );
                                                      
          -- Write the file header --                                                 
          UTL_FILE.PUT_LINE(
                                           v_div_writer,
                             RPT_HEADER,
                           TRUE
                          );
                                
      
        -- Write the detail line --                                                 
        v_piece := v_id_number                                   || CHR(9) ||                    
             v_label_name_line1                                 || CHR(9) ||            
             v_label_name_line2                                   || CHR(9) ||            
            v_sal_basic                                    || CHR(9) ||                    
             v_pref_street1                         || CHR(9) ||                
           v_pref_street2                          || CHR(9) ||                
           v_pref_street3                             || CHR(9) ||                
           v_pref_city_state_zip                                                     || CHR(9) ||          
           v_pledge_amount                   || CHR(9) ||
                         v_pledge_date_of_record                                   || CHR(9) ||        
           v_alloc_long_name                         || CHR(9) ||              
           v_pledge_amt_paid                      || CHR(9) ||              
           v_pledge_pay_amt                          || CHR(9) ||              
           v_balance_due                          || CHR(9) ||              
         v_pledge_type_desc;


          -- Write the transaction to the division report --                             UTL_FILE.PUT_LINE(
                                           v_div_writer,
                            v_piece,
                            FALSE
                          );
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 50 total points
ID: 22826425
you close and reopen the file on each pass through your cursor loop.

That is slow, just open it once before entering the loop and write to it until done then close after the cursor.


But, that's only performance,  the problem is when you close and reopen you are doing it with write mode 'w'
which overwrites the file each time instead of "a" for append which will add new data to the end of the file each time it is opened
0
 

Author Closing Comment

by:fprickett
ID: 31510932
Thank you so much, that fixed it.  You have taught me to fish!  (Give a man a fish, he eats for a day.  Teach a man how to fish, he eats for life.)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 22827451
glad I could help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Updating a field based from a if exist.... 2 31
sql query display the latest row 10 51
Powershell finalizing the end of an array. 4 23
Display field if column exists 7 30
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to take different types of Oracle backups using RMAN.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question